porffor 0.2.0-5e33105 → 0.2.0-6aff0fa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ import compile from '../compiler/wrap.js';
4
+ import fs from 'node:fs';
5
+
6
+ import Prefs from '../compiler/prefs.js';
7
+
8
+ const fast = Prefs.profiler === 'fast';
9
+
10
+ const file = process.argv.slice(2).find(x => x[0] !== '-');
11
+ let source = fs.readFileSync(file, 'utf8');
12
+
13
+ let profileId = 0;
14
+ source = fast ? source.replace(/^[^\n}]*;$/mg, _ => `profile(${profileId++});${_}profile(${profileId++});`) : source.replace(/^[^\n}]*;$/mg, _ => `profile(${profileId++});profile(${profileId++});${_}profile(${profileId++});`);
15
+
16
+ // console.log(source);
17
+
18
+ let tmp = new Array(profileId).fill(0);
19
+ let samples = 0;
20
+
21
+ const percents = process.argv.includes('-%');
22
+
23
+ const spinner = ['-', '\\', '|', '/'];
24
+ let spin = 0;
25
+ let last = 0;
26
+
27
+ try {
28
+ const { exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {
29
+ z: fast ? n => {
30
+ if (n % 2) {
31
+ tmp[n] += performance.now() - tmp[n - 1];
32
+ } else {
33
+ tmp[n] = performance.now();
34
+ }
35
+ } : n => {
36
+ if (n % 3 === 2) {
37
+ tmp[n] += (performance.now() - tmp[n - 1]) - (tmp[n - 1] - tmp[n - 2]);
38
+ samples++;
39
+
40
+ if (performance.now() > last) {
41
+ process.stdout.write(`\r${spinner[spin++ % 4]} running: collected ${samples} samples...`);
42
+ last = performance.now() + 100;
43
+ }
44
+ } else {
45
+ tmp[n] = performance.now();
46
+ }
47
+ }
48
+ });
49
+
50
+ const start = performance.now();
51
+
52
+ exports.main();
53
+
54
+ const total = performance.now() - start;
55
+
56
+ console.log(`\nsamples: ${fast ? 'not measured' : samples}\ntotal: ${total}ms\n\n` + source.split('\n').map(x => {
57
+ let time = 0;
58
+ if (x.startsWith('profile')) {
59
+ const id = parseInt(x.slice(8, x.indexOf(')')));
60
+ time = fast ? tmp[id + 1] : tmp[id + 2];
61
+ }
62
+
63
+ let color = [ 0, 0, 0 ];
64
+ if (time) {
65
+ const relativeTime = Math.sqrt(time / total);
66
+ if (percents) time = relativeTime;
67
+
68
+ color = [ (relativeTime * 250) | 0, (Math.sin(relativeTime * Math.PI) * 50) | 0, 0 ];
69
+ }
70
+
71
+ const ansiColor = `2;${color[0]};${color[1]};${color[2]}m`;
72
+
73
+ if (percents) return `\x1b[48;${ansiColor}\x1b[97m${time ? ((time * 100).toFixed(0).padStart(4, ' ') + '%') : ' '}\x1b[0m\x1b[38;${ansiColor}▌\x1b[0m ${x.replace(/profile\([0-9]+\);/g, '')}`;
74
+
75
+ let digits = 2;
76
+ if (time >= 100) digits = 1;
77
+ if (time >= 1000) digits = 0;
78
+
79
+ return `\x1b[48;${ansiColor}\x1b[97m${time ? time.toFixed(digits).padStart(6, ' ') : ' '}\x1b[0m\x1b[38;${ansiColor}▌\x1b[0m ${x.replace(/profile\([0-9]+\);/g, '')}`;
80
+ }).join('\n'));
81
+ } catch (e) {
82
+ console.error(e);
83
+ }
@@ -1,92 +0,0 @@
1
- var btoa_a = str => {
2
- // todo: throw invalid character for unicode
3
-
4
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
- const mask = (1 << 6) - 1;
6
-
7
- let out = '';
8
- let bits = 0, buffer = 0;
9
- for (let i = 0; i < str.length; i++) {
10
- buffer = (buffer << 8) | (0xff & str.charCodeAt(i));
11
- bits += 8;
12
-
13
- while (bits > 6) {
14
- bits -= 6;
15
- out += chars[mask & (buffer >> bits)];
16
- }
17
- }
18
-
19
- if (bits) {
20
- out += chars[mask & (buffer << (6 - bits))]
21
- }
22
-
23
- while ((out.length * 6) & 7) {
24
- out += '=';
25
- }
26
-
27
- return out;
28
- };
29
-
30
- var btoa = function (input) {
31
- // todo: throw invalid character for unicode
32
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
33
-
34
- let output = "";
35
- let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
36
- let i = 0;
37
-
38
- while (i < input.length) {
39
- chr1 = input.charCodeAt(i++);
40
- chr2 = input.charCodeAt(i++);
41
- chr3 = input.charCodeAt(i++);
42
-
43
- enc1 = chr1 >> 2;
44
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
45
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
46
- enc4 = chr3 & 63;
47
-
48
- if (isNaN(chr2)) {
49
- enc3 = enc4 = 64;
50
- } else if (isNaN(chr3)) {
51
- enc4 = 64;
52
- }
53
-
54
- output += keyStr.charAt(enc1);
55
- output += keyStr.charAt(enc2);
56
- output += keyStr.charAt(enc3);
57
- output += keyStr.charAt(enc4);
58
- }
59
-
60
- return output;
61
- };
62
-
63
- var atob_b = function (input) {
64
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
65
-
66
- let output = "";
67
- let chr1, chr2, chr3;
68
- let enc1, enc2, enc3, enc4;
69
- let i = 0;
70
-
71
- while (i < input.length) {
72
- enc1 = keyStr.indexOf(input.charAt(i++));
73
- enc2 = keyStr.indexOf(input.charAt(i++));
74
- enc3 = keyStr.indexOf(input.charAt(i++));
75
- enc4 = keyStr.indexOf(input.charAt(i++));
76
-
77
- chr1 = (enc1 << 2) | (enc2 >> 4);
78
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
79
- chr3 = ((enc3 & 3) << 6) | enc4;
80
-
81
- output += String.fromCharCode(chr1);
82
-
83
- if (enc3 != 64) {
84
- output += String.fromCharCode(chr2);
85
- }
86
- if (enc4 != 64) {
87
- output += String.fromCharCode(chr3);
88
- }
89
- }
90
-
91
- return output;
92
- };
package/node_trace.1.log DELETED
@@ -1 +0,0 @@
1
- {"traceEvents":[{"pid":13264,"tid":15096,"ts":95423117674,"tts":0,"ph":"X","cat":"v8","name":"V8.DeserializeIsolate","dur":4531,"tdur":0,"args":{}},{"pid":13264,"tid":15096,"ts":95423122578,"tts":0,"ph":"X","cat":"v8","name":"V8.DeserializeContext","dur":3271,"tdur":0,"args":{}},{"pid":13264,"tid":15096,"ts":95423130539,"tts":0,"ph":"X","cat":"v8","name":"V8.DeserializeContext","dur":346,"tdur":0,"args":{}},{"pid":13264,"tid":15096,"ts":95423152512,"tts":0,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":4996680,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423152519,"tts":0,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":431,"tdur":0,"args":{}},{"pid":13264,"tid":15096,"ts":95423152969,"tts":0,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":4389296}},{"pid":13264,"tid":15096,"ts":95423160029,"tts":0,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":4924936,"type":"task"}},{"pid":13264,"tid":15096,"ts":95423160032,"tts":0,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":324,"tdur":0,"args":{}},{"pid":13264,"tid":15096,"ts":95423160367,"tts":0,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":4440256}},{"pid":13264,"tid":15096,"ts":95423175256,"tts":67346,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":6472768,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423175267,"tts":67356,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":299,"tdur":300,"args":{}},{"pid":13264,"tid":15096,"ts":95423175578,"tts":67667,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":5881080}},{"pid":13264,"tid":15096,"ts":95423188220,"tts":80241,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":6928320,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423188222,"tts":80243,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":363,"tdur":362,"args":{}},{"pid":13264,"tid":15096,"ts":95423188596,"tts":80616,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":6372328}},{"pid":13264,"tid":15096,"ts":95423191843,"tts":83862,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":8430312,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423191845,"tts":83864,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":258,"tdur":239,"args":{}},{"pid":13264,"tid":15096,"ts":95423192113,"tts":84113,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":6741768}},{"pid":13264,"tid":15096,"ts":95423199261,"tts":91198,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":8882104,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423199264,"tts":91200,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":256,"tdur":220,"args":{}},{"pid":13264,"tid":15096,"ts":95423199530,"tts":91430,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":6991296}},{"pid":13264,"tid":15096,"ts":95423203033,"tts":94931,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":9582528,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423203035,"tts":94933,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":147,"tdur":128,"args":{}},{"pid":13264,"tid":15096,"ts":95423203191,"tts":95069,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":7206184}},{"pid":13264,"tid":15096,"ts":95423207062,"tts":98940,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":10032360,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423207063,"tts":98941,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":98,"tdur":98,"args":{}},{"pid":13264,"tid":15096,"ts":95423207169,"tts":99046,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":7617064}},{"pid":13264,"tid":15096,"ts":95423210148,"tts":102008,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":10442184,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95423210149,"tts":102009,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":83,"tdur":82,"args":{}},{"pid":13264,"tid":15096,"ts":95423210241,"tts":102101,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":7743728}},{"pid":13264,"tid":15096,"ts":95598120854,"tts":172740055,"ph":"B","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":10650144,"type":"allocation failure"}},{"pid":13264,"tid":15096,"ts":95598120861,"tts":172740060,"ph":"X","cat":"v8","name":"V8.GCScavenger","dur":188,"tdur":189,"args":{}},{"pid":13264,"tid":15096,"ts":95598121065,"tts":172740264,"ph":"E","cat":"devtools.timeline,v8","name":"MinorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":8016624}},{"pid":13264,"tid":15096,"ts":95707243189,"tts":280108308,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":20,"tdur":19,"args":{}},{"pid":13264,"tid":15096,"ts":95707243201,"tts":280108319,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":8,"tdur":8,"args":{}},{"pid":13264,"tid":15096,"ts":95707244259,"tts":280109369,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":10,"tdur":8,"args":{}},{"pid":13264,"tid":15096,"ts":95707244265,"tts":280109374,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":3,"tdur":3,"args":{}},{"pid":13264,"tid":15096,"ts":95707244376,"tts":280109452,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":9,"tdur":8,"args":{}},{"pid":13264,"tid":15096,"ts":95707244381,"tts":280109456,"ph":"X","cat":"v8","name":"V8.DeoptimizeCode","dur":3,"tdur":4,"args":{}},{"pid":13264,"tid":15096,"ts":95707245192,"tts":280110267,"ph":"X","cat":"v8","name":"V8.GCIncrementalMarkingStart","dur":214,"tdur":214,"args":{"epoch":11,"reason":"memory reducer"}},{"pid":13264,"tid":15096,"ts":95707245464,"tts":280110540,"ph":"X","cat":"v8","name":"V8.GCIncrementalMarking","dur":7,"tdur":6,"args":{"epoch":11}},{"pid":13264,"tid":15096,"ts":95707245559,"tts":280110634,"ph":"B","cat":"devtools.timeline,v8","name":"MajorGC","dur":0,"tdur":0,"args":{"usedHeapSizeBefore":8366408,"type":"external finalize"}},{"pid":13264,"tid":15096,"ts":95707245561,"tts":280110635,"ph":"X","cat":"v8","name":"V8.GCFinalizeMCReduceMemory","dur":1914,"tdur":1617,"args":{}},{"pid":13264,"tid":15096,"ts":95707247497,"tts":280112273,"ph":"E","cat":"devtools.timeline,v8","name":"MajorGC","dur":0,"tdur":0,"args":{"usedHeapSizeAfter":6173808}},{"pid":13264,"tid":15096,"ts":95423116966,"tts":0,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"Command Prompt - node --trace-event-categories v8 runner/index.js bench/bf.js"}},{"pid":13264,"tid":15096,"ts":95423116967,"tts":0,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"21.6.0"}},{"pid":13264,"tid":15096,"ts":95423116968,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":13264,"tid":15096,"ts":95423116978,"tts":0,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"21.6.0","v8":"11.8.172.17-node.19","uv":"1.47.0","zlib":"1.3.0.1-motley-40e35a7","brotli":"1.1.0","ares":"1.20.1","modules":"120","nghttp2":"1.58.0","napi":"9","llhttp":"9.1.3","uvwasi":"0.0.19","acorn":"8.11.3","simdjson":"3.6.3","simdutf":"4.0.8","ada":"2.7.4","undici":"5.28.2","cjs_module_lexer":"1.2.2","base64":"0.5.1","openssl":"3.0.12+quic","cldr":"44.0","icu":"74.1","tz":"2023c","unicode":"15.1","ngtcp2":"0.8.1","nghttp3":"0.7.0"},"arch":"x64","platform":"win32","release":{"name":"node"}}}},{"pid":13264,"tid":9152,"ts":95423117058,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"WorkerThreadsTaskRunner::DelayedTaskScheduler"}},{"pid":13264,"tid":12304,"ts":95423117145,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":11816,"ts":95423117184,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":5044,"ts":95423117206,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":4032,"ts":95423117236,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":15096,"ts":95423116966,"tts":0,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"Command Prompt - node --trace-event-categories v8 runner/index.js bench/bf.js"}},{"pid":13264,"tid":15096,"ts":95423116967,"tts":0,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"21.6.0"}},{"pid":13264,"tid":15096,"ts":95423116968,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":13264,"tid":15096,"ts":95423116978,"tts":0,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"21.6.0","v8":"11.8.172.17-node.19","uv":"1.47.0","zlib":"1.3.0.1-motley-40e35a7","brotli":"1.1.0","ares":"1.20.1","modules":"120","nghttp2":"1.58.0","napi":"9","llhttp":"9.1.3","uvwasi":"0.0.19","acorn":"8.11.3","simdjson":"3.6.3","simdutf":"4.0.8","ada":"2.7.4","undici":"5.28.2","cjs_module_lexer":"1.2.2","base64":"0.5.1","openssl":"3.0.12+quic","cldr":"44.0","icu":"74.1","tz":"2023c","unicode":"15.1","ngtcp2":"0.8.1","nghttp3":"0.7.0"},"arch":"x64","platform":"win32","release":{"name":"node"}}}},{"pid":13264,"tid":9152,"ts":95423117058,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"WorkerThreadsTaskRunner::DelayedTaskScheduler"}},{"pid":13264,"tid":12304,"ts":95423117145,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":11816,"ts":95423117184,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":5044,"ts":95423117206,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}},{"pid":13264,"tid":4032,"ts":95423117236,"tts":0,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"PlatformWorkerThread"}}]}
package/runner/profile.js DELETED
@@ -1,46 +0,0 @@
1
- import compile from '../compiler/index.js';
2
- import fs from 'node:fs';
3
-
4
- let csv = `phase,time\n`;
5
-
6
- csv += `node,${performance.now()}\n`;
7
-
8
- const t0 = performance.now();
9
- const file = process.argv.slice(2).find(x => x[0] !== '-');
10
- const source = fs.readFileSync(file, 'utf8');
11
- csv += `read,${performance.now() - t0}\n`;
12
-
13
- console.log = x => {
14
- if (x.includes(' in ')) {
15
- csv += [ 'parse', 'codegen', 'opt', 'sections' ][parseInt(x[0]) - 1] + ',' + x.split(' in ')[1].slice(0, -2) + '\n';
16
- }
17
- };
18
-
19
- const wasm = compile(source, [ 'info' ]);
20
-
21
- let cache = '';
22
- const print = str => {
23
- cache += str;
24
-
25
- if (str === '\n') {
26
- process.stdout.write(cache);
27
- cache = '';
28
- }
29
- };
30
-
31
- const t1 = performance.now();
32
- const { instance } = await WebAssembly.instantiate(wasm, {
33
- '': {
34
- p: i => print(Number(i).toString()),
35
- c: i => print(String.fromCharCode(Number(i)))
36
- }
37
- });
38
- csv += `inst,${performance.now() - t1}\n`;
39
-
40
- const t2 = performance.now();
41
- instance.exports.m();
42
- print('\n');
43
-
44
- csv += `exec,${performance.now() - t2}`;
45
-
46
- fs.writeFileSync(`profile.csv`, csv);