Skip to content

Commit d299223

Browse files
♻️ refactor(profile): Write better code and add analysis script.
1 parent 2fd09fc commit d299223

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

_profile/analyze.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env sh
2+
3+
TIMESTAMP="$(date '+%Y-%m-%dT%H:%M:%S')"
4+
5+
logfile="$(printf '%s-' "$@")${TIMESTAMP}-analyze-v8.log"
6+
7+
node --prof --log-all --logfile="$logfile" "$@"

_profile/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"scripts": {
44
"build-cmd": "babel --delete-dir-on-start",
55
"build:profile": "yarn build-cmd --env-name profile --out-dir dist/profile ../src",
6+
"analyze": "sh analyze.sh",
67
"profile": "sh profile.sh"
78
},
89
"dependencies": {

_profile/push.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
console.time('prepare');
2-
require('regenerator-runtime/runtime');
3-
const ArgumentParser = require('argparse').ArgumentParser;
4-
const empty = require('..').empty;
1+
import 'regenerator-runtime/runtime.js';
2+
import {ArgumentParser} from 'argparse';
3+
import {FAST_COUNTER as COUNTER} from '../test/src/_fixtures.js';
4+
import {empty} from './dist/profile/index.js';
55

6-
const COUNTER = {
7-
plus(a, b) {
8-
return a + b;
9-
},
10-
measure(_x) {
11-
return 1;
12-
},
13-
zero() {
14-
return 0;
15-
},
16-
};
6+
console.time('prepare');
177

188
const parser = new ArgumentParser();
199
parser.add_argument('M', {default: 1000, nargs: '?'});
@@ -30,7 +20,7 @@ console.timeEnd('prepare');
3020
console.time('push');
3121
for (let k = 0; k < N; ++k) {
3222
let x = t;
33-
for (let i = 0; i < M; ++i) x = x.push();
23+
for (let i = 0; i < M; ++i) x = x.push(i);
3424
}
3525

3626
console.timeEnd('push');

0 commit comments

Comments
 (0)