Skip to content

Commit

Permalink
feat: finishing up the test, now for automation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePrimeagen committed Sep 19, 2023
1 parent 87c43e6 commit ab513a3
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 11 deletions.
40 changes: 40 additions & 0 deletions node.mem
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
11.9883 MB
52.8125 MB
52.8125 MB
52.8125 MB
52.8125 MB
52.8125 MB
52.8125 MB
52.8125 MB
52.8125 MB
48.5234 MB
48.5234 MB
48.5234 MB
48.5234 MB
54.6367 MB
112.062 MB
141.711 MB
165.762 MB
207.523 MB
227.41 MB
239.781 MB
300.625 MB
307.449 MB
310.285 MB
357.715 MB
419.074 MB
446.391 MB
447.164 MB
448.453 MB
464.172 MB
520.633 MB
592.305 MB
662.945 MB
669.281 MB
681.652 MB
682.637 MB
683.668 MB
685.215 MB
715.121 MB
789.887 MB
795.816 MB
109 changes: 108 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "perf-machine",
"module": "src/index.ts",
"devDependencies": {
"@types/lodash": "^4.14.198",
"@types/react": "^18.2.22",
"@types/redux": "^3.6.0",
"bun-types": "latest"
},
"peerDependencies": {
Expand All @@ -12,6 +15,9 @@
"assert": "^2.1.0",
"body-parser": "^1.20.2",
"express": "^4.18.2",
"hono": "^3.6.1"
"hono": "^3.6.1",
"lodash": "^4.17.21",
"react": "^18.2.0",
"redux": "^4.2.1"
}
}
19 changes: 19 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

kill -9 $(lsof -ti :42069)

vmrss() {
p=$1
while true; do sync; cat /proc/$p/status |grep VmRSS|grep -o '[0-9]\+'| awk '{print $1/1024 " MB"}'; sleep 1; done
}

if [ "$1" == "bun" ]; then
echo "Running bun"
bun --bun src/index.ts &
else
echo "Running node"
node dist/index.js &
fi
pid=$!

vmrss $pid | tee $2.mem
27 changes: 26 additions & 1 deletion run_many
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

counter=$1
tsc -p tsconfig.node.json
counter=$1
start_node=$(date +%s%N | cut -b1-13)

echo "starting at: $start_node"
Expand All @@ -27,6 +27,31 @@ end_bun=$(date +%s%N | cut -b1-13)

echo "bun took: $(( $end_bun - $start_bun ))"

counter=$1
start_node=$(date +%s%N | cut -b1-13)
echo "starting at: $start_node"
while [ $counter -gt 0 ]
do
node dist/startup.slow.js 1>/dev/null
counter=$(( $counter - 1 ))
done
end_node=$(date +%s%N | cut -b1-13)

echo "node took: $(( $end_node - $start_node ))"

counter=$1
start_bun=$(date +%s%N | cut -b1-13)

echo "starting at: $start_bun"
while [ $counter -gt 0 ]
do
bun --bun dist/startup.slow.js 1>/dev/null
counter=$(( $counter - 1 ))
done
end_bun=$(date +%s%N | cut -b1-13)

echo "bun took: $(( $end_bun - $start_bun ))"

counter=$1
start_go=$(date +%s%N | cut -b1-13)
echo "starting at: $start_go"
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Runnable = {
const methodList: Record<string, Runnable> = methods as any;

app.use(bodyParser.json());
app.use(bodyParser.text());

app.post('/', async (req, res) => {
const method = req.headers["x-method"];
Expand All @@ -22,7 +23,7 @@ app.post('/', async (req, res) => {
}

const out = await found.run(req);
res.status(200).send(out);
res.status(200).send(String(out));
});

app.post('/setup', async (req, res) => {
Expand Down
20 changes: 20 additions & 0 deletions src/startup.slow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import _ from "lodash";
import redux from "redux";
import express from "express";
import bodyParser from "body-parser";

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.text());

app.post('/', async (req, res) => {
res.status(200).send("");
});

app.post('/setup', async (req, res) => {
res.status(200).send("");
});

console.log(`${String(React)} -- ${_} -- ${String(redux)}`);

6 changes: 6 additions & 0 deletions src/tests/data
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
ntheutnhoeuth,rc.uhnoeuhnoeuheuhnoeuhoneuhaseuhsaeudaoteidaeuhsathoeidaehusatdeitaseuhstaodeintaedutadoeitndaoesutdatoeidaseuhtasoeidtaeuhtasodeitaeuhtaosediaseduntasodeiaehusatodeintaseuhnaostdeitaeuhasedinaeuhnasteidtsaeuhtaseidnaoeshu2nateuntaheutnaheu
6 changes: 6 additions & 0 deletions src/tests/data2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
notehuntoehuntoehuntoheuntoheutnh0.0.0.0ntoheuntoheuntoheuntoheuntoheuntoheuntoheunthoe
3 changes: 3 additions & 0 deletions src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export * as structuredCopy from "./structuredCopy";
export * as gc from "./gc";
export * as timeout from "./setTimeout";
export * as file from "./file";
export * as regex from "./regex";
export * as regexLong from "./regexLong";
export * as parsing from "./parsing";
7 changes: 0 additions & 7 deletions src/tests/json-copy.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/tests/parsing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
async function requireModule(moduleName: string): Promise<string> {
const m = require(moduleName);
const out = String(m);
delete require.cache[require.resolve(moduleName)];

return out;
}

export function run(req: Request) {
return requireModule(req.body as any as string);
}


11 changes: 11 additions & 0 deletions src/tests/regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


function findTheFirstDigit(str: string) {
return str.search(/\d/);
}

export function run(req: Request) {
const data = req.body as any as string;
return data.split("\n").map(findTheFirstDigit).reduce((acc, line) => acc + line, 0);
}

10 changes: 10 additions & 0 deletions src/tests/regexLong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function findTheFirstDigit(str: string) {
return str.search(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/);
}

export function run(req: Request) {
const data = req.body as any as string;
return data.split("\n").map(findTheFirstDigit).reduce((acc, line) => acc + line, 0);
}


0 comments on commit ab513a3

Please sign in to comment.