typenative 0.7.0 → 0.7.1
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.
- package/bin/node/assert.js +2 -2
- package/bin/node/child_process.js +66 -8
- package/bin/node/fs.js +1012 -4
- package/bin/node/histogram.js +1991 -0
- package/bin/node/process.js +14 -2
- package/bin/node/sqlite.js +1488 -5
- package/bin/node/stream.js +2 -1
- package/bin/node/system_extra.js +3 -270
- package/bin/node/test.js +39 -1
- package/bin/node/test_report.js +47 -1
- package/bin/node/test_run.js +57 -2
- package/bin/node/util.js +8 -5
- package/bin/node/webassembly.js +20 -5
- package/bin/node/webview.js +3257 -244
- package/bin/node/zlib.js +118 -14
- package/bin/node/zlib_iter.js +585 -0
- package/bin/transpiler.js +1370 -258
- package/bin/version.js +1 -1
- package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
- package/package.json +10 -1
- package/types/tsconfig.json +17 -0
- package/types/typenative-npm.d.ts +492 -12
- package/types/typenative.d.ts +88 -2
- package/.gitattributes +0 -1
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/npm-publish-github-packages.yml +0 -88
- package/CHANGELOG.md +0 -1746
- package/CONTRIBUTION.md +0 -133
- package/conformance.md +0 -1497
- package/examples/README.md +0 -114
- package/examples/angular-templates/README.md +0 -141
- package/examples/angular-templates/bench.mjs +0 -173
- package/examples/angular-templates/dom-type-globals.d.ts +0 -21
- package/examples/angular-templates/dom-type-stubs.ts +0 -21
- package/examples/angular-templates/main.ts +0 -135
- package/examples/angular-templates/parity.mjs +0 -157
- package/examples/angular-templates/run-node.mjs +0 -69
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
- package/examples/desktop-notes/README.md +0 -106
- package/examples/desktop-notes/bench.mjs +0 -125
- package/examples/desktop-notes/main.ts +0 -131
- package/examples/desktop-notes/package-lock.json +0 -726
- package/examples/desktop-notes/package.json +0 -9
- package/examples/desktop-notes/ui.ts +0 -176
- package/examples/dupe-finder/README.md +0 -78
- package/examples/dupe-finder/bench.mjs +0 -120
- package/examples/dupe-finder/main.ts +0 -87
- package/examples/fibonacci/README.md +0 -89
- package/examples/fibonacci/bench.mjs +0 -87
- package/examples/fibonacci/main.ts +0 -21
- package/examples/hello-world/README.md +0 -62
- package/examples/hello-world/bench.mjs +0 -66
- package/examples/hello-world/main.ts +0 -7
- package/examples/json-server/README.md +0 -132
- package/examples/json-server/bench.mjs +0 -263
- package/examples/json-server/main.ts +0 -67
- package/examples/mandelbrot-png/README.md +0 -63
- package/examples/mandelbrot-png/bench.mjs +0 -95
- package/examples/mandelbrot-png/main.ts +0 -98
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +0 -174
- package/examples/marked-cli/bench.mjs +0 -178
- package/examples/marked-cli/main.ts +0 -410
- package/examples/marked-cli/parity.mjs +0 -185
- package/examples/marked-cli/vendor/marked/LICENSE +0 -44
- package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
- package/examples/openai-chat/README.md +0 -148
- package/examples/openai-chat/bench.mjs +0 -175
- package/examples/openai-chat/main.ts +0 -488
- package/examples/react-compiler/README.md +0 -185
- package/examples/react-compiler/bench.mjs +0 -181
- package/examples/react-compiler/main.ts +0 -324
- package/examples/react-compiler/parity.mjs +0 -362
- package/examples/react-compiler/run-node.mjs +0 -90
- package/examples/react-compiler/vendor/babel/LICENSE +0 -22
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
- package/examples/react-compiler/vendor/charcodes/package.json +0 -25
- package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
- package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
- package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
- package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
- package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
- package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
- package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
- package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
- package/examples/react-compiler/vendor/zod/LICENSE +0 -21
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
- package/examples/react-compiler/vendor.mjs +0 -688
- package/examples/todo-cli/README.md +0 -69
- package/examples/todo-cli/bench.mjs +0 -89
- package/examples/todo-cli/main.ts +0 -92
- package/examples/yaml-cli/README.md +0 -152
- package/examples/yaml-cli/bench.mjs +0 -265
- package/examples/yaml-cli/main.ts +0 -251
- package/examples/yaml-cli/parity.mjs +0 -156
- package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
- package/performance/README.md +0 -248
- package/performance/any-dynamic.ts +0 -21
- package/performance/any-record-view.ts +0 -20
- package/performance/arr-for-of.ts +0 -29
- package/performance/arr-hof.ts +0 -21
- package/performance/arr-push-index.ts +0 -15
- package/performance/arr-push-local.ts +0 -39
- package/performance/arr-slice-concat.ts +0 -24
- package/performance/arr-sort.ts +0 -21
- package/performance/async-await.ts +0 -24
- package/performance/async-promise-all.ts +0 -38
- package/performance/bigint-arith.ts +0 -36
- package/performance/buf-encode.ts +0 -29
- package/performance/class-accessors.ts +0 -48
- package/performance/class-dispatch.ts +0 -52
- package/performance/date-format.ts +0 -18
- package/performance/events-emit.ts +0 -27
- package/performance/exc-throw-rare.ts +0 -25
- package/performance/exc-try-catch.ts +0 -26
- package/performance/fn-closures.ts +0 -29
- package/performance/fn-recursion-tree.ts +0 -31
- package/performance/fn-rest-spread.ts +0 -43
- package/performance/gen-for-of.ts +0 -46
- package/performance/gen-next.ts +0 -32
- package/performance/iter-helpers.ts +0 -38
- package/performance/json-any.ts +0 -30
- package/performance/json-roundtrip.ts +0 -27
- package/performance/map-delete.ts +0 -24
- package/performance/map-iterate.ts +0 -26
- package/performance/map-number-keys.ts +0 -37
- package/performance/map-string-keys.ts +0 -22
- package/performance/num-arith-loop.ts +0 -14
- package/performance/num-bitwise.ts +0 -21
- package/performance/num-hash-imul.ts +0 -36
- package/performance/num-mod-int.ts +0 -16
- package/performance/num-to-string.ts +0 -16
- package/performance/obj-alloc.ts +0 -32
- package/performance/obj-keys-entries.ts +0 -44
- package/performance/obj-optional-chain.ts +0 -42
- package/performance/obj-record-dict.ts +0 -24
- package/performance/obj-spread-destructure.ts +0 -40
- package/performance/regex-exec.ts +0 -29
- package/performance/regex-replace-fn.ts +0 -24
- package/performance/regex-site.ts +0 -28
- package/performance/set-ops.ts +0 -20
- package/performance/str-char-scan.ts +0 -35
- package/performance/str-concat-plus.ts +0 -18
- package/performance/str-concat.ts +0 -24
- package/performance/str-methods.ts +0 -24
- package/performance/str-short-scan.ts +0 -26
- package/performance/str-split-join.ts +0 -23
- package/performance/str-switch-compare.ts +0 -50
- package/performance/str-template.ts +0 -16
- package/performance/str-unicode.ts +0 -25
- package/performance/typed-array.ts +0 -30
- package/performance/union-switch.ts +0 -57
- package/performance/union-typeof.ts +0 -40
- package/performance/wasm-call.ts +0 -63
- package/tsparser/check.go +0 -158
- package/tsparser/go.mod +0 -14
- package/tsparser/go.sum +0 -22
- package/tsparser/main.go +0 -363
- package/tsparser/tsparser.exe +0 -4
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// perf: virtual method calls through an abstract base class and an interface
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
interface Shape {
|
|
5
|
-
area(): number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
abstract class Base implements Shape {
|
|
9
|
-
abstract area(): number;
|
|
10
|
-
scaled(k: number): number {
|
|
11
|
-
return this.area() * k;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class Square extends Base {
|
|
16
|
-
side: number;
|
|
17
|
-
constructor(side: number) {
|
|
18
|
-
super();
|
|
19
|
-
this.side = side;
|
|
20
|
-
}
|
|
21
|
-
area(): number {
|
|
22
|
-
return this.side * this.side;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class Rect extends Base {
|
|
27
|
-
w: number;
|
|
28
|
-
h: number;
|
|
29
|
-
constructor(w: number, h: number) {
|
|
30
|
-
super();
|
|
31
|
-
this.w = w;
|
|
32
|
-
this.h = h;
|
|
33
|
-
}
|
|
34
|
-
area(): number {
|
|
35
|
-
return this.w * this.h;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const shapes: Base[] = [];
|
|
40
|
-
for (let i = 0; i < 1000; i++) shapes.push(i % 2 === 0 ? new Square(i % 10) : new Rect(i % 7, 3));
|
|
41
|
-
const asIface: Shape[] = shapes;
|
|
42
|
-
|
|
43
|
-
const start = performance.now();
|
|
44
|
-
let total = 0;
|
|
45
|
-
for (let pass = 0; pass < 25000; pass++) {
|
|
46
|
-
for (let i = 0; i < shapes.length; i++) total += shapes[i].scaled(2);
|
|
47
|
-
for (const s of asIface) total += s.area();
|
|
48
|
-
}
|
|
49
|
-
const elapsed = performance.now() - start;
|
|
50
|
-
|
|
51
|
-
console.log(`checksum: ${total}`);
|
|
52
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// perf: `new Date(ms)`, UTC getters, `toISOString` and `Date.parse` (timestamps in log lines)
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const BASE = Date.UTC(2024, 0, 1);
|
|
5
|
-
|
|
6
|
-
const start = performance.now();
|
|
7
|
-
let total = 0;
|
|
8
|
-
for (let i = 0; i < 150_000; i++) {
|
|
9
|
-
const d = new Date(BASE + i * 37_000_123);
|
|
10
|
-
total += d.getUTCFullYear() + d.getUTCMonth() + d.getUTCDate() + d.getUTCHours() + d.getUTCDay();
|
|
11
|
-
const iso = d.toISOString();
|
|
12
|
-
total += iso.charCodeAt(9) + iso.charCodeAt(15);
|
|
13
|
-
if ((i & 7) === 0) total += (Date.parse(iso) - BASE) & 1023;
|
|
14
|
-
}
|
|
15
|
-
const elapsed = performance.now() - start;
|
|
16
|
-
|
|
17
|
-
console.log(`checksum: ${total}`);
|
|
18
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// perf: `EventEmitter` `emit` to listeners taking 0, 1 and 2 arguments
|
|
2
|
-
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { performance } from 'node:perf_hooks';
|
|
4
|
-
|
|
5
|
-
const bus = new EventEmitter();
|
|
6
|
-
let total = 0;
|
|
7
|
-
bus.on('tick', () => {
|
|
8
|
-
total++;
|
|
9
|
-
});
|
|
10
|
-
bus.on('data', (n: number) => {
|
|
11
|
-
total += n & 7;
|
|
12
|
-
});
|
|
13
|
-
bus.on('pair', (a: number, b: string) => {
|
|
14
|
-
total += a + b.length;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const n = 3_000_000;
|
|
18
|
-
const start = performance.now();
|
|
19
|
-
for (let i = 0; i < n; i++) {
|
|
20
|
-
bus.emit('tick');
|
|
21
|
-
bus.emit('data', i);
|
|
22
|
-
bus.emit('pair', i & 3, 'ab');
|
|
23
|
-
}
|
|
24
|
-
const elapsed = performance.now() - start;
|
|
25
|
-
|
|
26
|
-
console.log(`checksum: ${total}`);
|
|
27
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// perf: `try`/`catch`/`finally` in a hot loop where nothing throws
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function step(i: number): number {
|
|
5
|
-
if (i < 0) throw new Error('negative');
|
|
6
|
-
return i & 255;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const n = 50_000_000;
|
|
10
|
-
const start = performance.now();
|
|
11
|
-
let total = 0;
|
|
12
|
-
let cleanups = 0;
|
|
13
|
-
for (let i = 0; i < n; i++) {
|
|
14
|
-
try {
|
|
15
|
-
total += step(i);
|
|
16
|
-
} catch (e) {
|
|
17
|
-
total -= 1;
|
|
18
|
-
} finally {
|
|
19
|
-
cleanups++;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const elapsed = performance.now() - start;
|
|
23
|
-
|
|
24
|
-
console.log(`checksum: ${total + cleanups}`);
|
|
25
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// perf: `try`/`catch`/`finally` in a hot loop where one call in 1,024 throws
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function risky(i: number): number {
|
|
5
|
-
if ((i & 1023) === 0) throw new Error('bad ' + i);
|
|
6
|
-
return i & 7;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const n = 10_000_000;
|
|
10
|
-
|
|
11
|
-
const start = performance.now();
|
|
12
|
-
let total = 0;
|
|
13
|
-
let caught = 0;
|
|
14
|
-
for (let i = 0; i < n; i++) {
|
|
15
|
-
try {
|
|
16
|
-
total += risky(i);
|
|
17
|
-
} catch (e) {
|
|
18
|
-
caught++;
|
|
19
|
-
} finally {
|
|
20
|
-
total++;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const elapsed = performance.now() - start;
|
|
24
|
-
|
|
25
|
-
console.log(`checksum: ${total + caught}`);
|
|
26
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// perf: creating closures over mutable state and calling them indirectly
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function makeCounter(step: number): () => number {
|
|
5
|
-
let count = 0;
|
|
6
|
-
return () => {
|
|
7
|
-
count += step;
|
|
8
|
-
return count;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function apply(f: (x: number) => number, x: number): number {
|
|
13
|
-
return f(x);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const n = 12_000_000;
|
|
17
|
-
|
|
18
|
-
const start = performance.now();
|
|
19
|
-
let total = 0;
|
|
20
|
-
for (let i = 0; i < n; i++) {
|
|
21
|
-
const next = makeCounter(i & 3);
|
|
22
|
-
next();
|
|
23
|
-
total += next();
|
|
24
|
-
total += apply((x) => x + (i & 1), 1);
|
|
25
|
-
}
|
|
26
|
-
const elapsed = performance.now() - start;
|
|
27
|
-
|
|
28
|
-
console.log(`checksum: ${total}`);
|
|
29
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// perf: building and walking binary trees (recursion plus allocation)
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
class TreeNode {
|
|
5
|
-
left: TreeNode | null;
|
|
6
|
-
right: TreeNode | null;
|
|
7
|
-
constructor(left: TreeNode | null, right: TreeNode | null) {
|
|
8
|
-
this.left = left;
|
|
9
|
-
this.right = right;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function make(depth: number): TreeNode {
|
|
14
|
-
return depth === 0 ? new TreeNode(null, null) : new TreeNode(make(depth - 1), make(depth - 1));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function check(node: TreeNode): number {
|
|
18
|
-
if (node.left === null || node.right === null) return 1;
|
|
19
|
-
return 1 + check(node.left) + check(node.right);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const start = performance.now();
|
|
23
|
-
let total = 0;
|
|
24
|
-
for (let depth = 4; depth <= 16; depth += 2) {
|
|
25
|
-
const iterations = 1 << (16 - depth + 4);
|
|
26
|
-
for (let i = 0; i < iterations; i++) total += check(make(depth));
|
|
27
|
-
}
|
|
28
|
-
const elapsed = performance.now() - start;
|
|
29
|
-
|
|
30
|
-
console.log(`checksum: ${total}`);
|
|
31
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// perf: rest parameters, spread arguments `f(...args)`, default parameters and `.call` / `.apply` / `.bind`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function sum(...xs: number[]): number {
|
|
5
|
-
let s = 0;
|
|
6
|
-
for (let i = 0; i < xs.length; i++) s += xs[i];
|
|
7
|
-
return s;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function scaled(x: number, factor = 2, bias = 1): number {
|
|
11
|
-
return x * factor + bias;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class Acc {
|
|
15
|
-
base: number;
|
|
16
|
-
constructor(base: number) {
|
|
17
|
-
this.base = base;
|
|
18
|
-
}
|
|
19
|
-
add(a: number, b: number): number {
|
|
20
|
-
return this.base + a + b;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const acc = new Acc(3);
|
|
25
|
-
// (the original receiver: `.call` / `.bind` with another object ignore it in TypeNative, see the README)
|
|
26
|
-
const bound = acc.add.bind(acc);
|
|
27
|
-
const args = [1, 2, 3, 4];
|
|
28
|
-
|
|
29
|
-
const start = performance.now();
|
|
30
|
-
let total = 0;
|
|
31
|
-
for (let i = 0; i < 5_000_000; i++) {
|
|
32
|
-
const k = i & 15;
|
|
33
|
-
total += sum(k, 1, 2);
|
|
34
|
-
total += sum(...args);
|
|
35
|
-
total += scaled(k) + scaled(k, 3);
|
|
36
|
-
total += acc.add.call(acc, k, 1);
|
|
37
|
-
total += acc.add.apply(acc, [k, 2]);
|
|
38
|
-
total += bound(k, 0);
|
|
39
|
-
}
|
|
40
|
-
const elapsed = performance.now() - start;
|
|
41
|
-
|
|
42
|
-
console.log(`checksum: ${total}`);
|
|
43
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// perf: sync generators (a method, `*[Symbol.iterator]()`, `yield*`) consumed by `for…of`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
class Op {
|
|
5
|
-
value: number;
|
|
6
|
-
constructor(value: number) {
|
|
7
|
-
this.value = value;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class OpList {
|
|
12
|
-
private items: Op[] = [];
|
|
13
|
-
push(op: Op): void {
|
|
14
|
-
this.items.push(op);
|
|
15
|
-
}
|
|
16
|
-
*[Symbol.iterator](): Generator<Op> {
|
|
17
|
-
for (let i = 0; i < this.items.length; i++) yield this.items[i];
|
|
18
|
-
}
|
|
19
|
-
*reversed(): Generator<Op> {
|
|
20
|
-
for (let i = this.items.length - 1; i >= 0; i--) yield this.items[i];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function* range(n: number): Generator<number> {
|
|
25
|
-
for (let i = 0; i < n; i++) yield i;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function* both(list: OpList): Generator<Op> {
|
|
29
|
-
yield* list.reversed();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const list = new OpList();
|
|
33
|
-
for (let i = 0; i < 2000; i++) list.push(new Op(i));
|
|
34
|
-
|
|
35
|
-
const start = performance.now();
|
|
36
|
-
let total = 0;
|
|
37
|
-
for (let pass = 0; pass < 500; pass++) {
|
|
38
|
-
for (const op of list) total += op.value;
|
|
39
|
-
for (const op of list.reversed()) total -= op.value >> 1;
|
|
40
|
-
for (const i of range(2000)) total += i & 7;
|
|
41
|
-
for (const op of both(list)) total += op.value & 3;
|
|
42
|
-
}
|
|
43
|
-
const elapsed = performance.now() - start;
|
|
44
|
-
|
|
45
|
-
console.log(`checksum: ${total}`);
|
|
46
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
package/performance/gen-next.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// perf: generators driven by hand (`.next()`), spread `[...gen()]` and stored in a variable before `for…of`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function* range(n: number): Generator<number> {
|
|
5
|
-
for (let i = 0; i < n; i++) yield i;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function* pairs(n: number): Generator<[number, number]> {
|
|
9
|
-
for (let i = 0; i < n; i++) yield [i, i * 2];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const start = performance.now();
|
|
13
|
-
let total = 0;
|
|
14
|
-
for (let pass = 0; pass < 24000; pass++) {
|
|
15
|
-
// manual .next()
|
|
16
|
-
const it = range(64);
|
|
17
|
-
let r = it.next();
|
|
18
|
-
while (!r.done) {
|
|
19
|
-
total += r.value & 7;
|
|
20
|
-
r = it.next();
|
|
21
|
-
}
|
|
22
|
-
// spread
|
|
23
|
-
const all = [...range(32)];
|
|
24
|
-
total += all.length + all[pass & 31];
|
|
25
|
-
// a stored generator consumed by for…of
|
|
26
|
-
const stored = pairs(32);
|
|
27
|
-
for (const [a, b] of stored) total += (a ^ b) & 3;
|
|
28
|
-
}
|
|
29
|
-
const elapsed = performance.now() - start;
|
|
30
|
-
|
|
31
|
-
console.log(`checksum: ${total}`);
|
|
32
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// perf: ES2025 iterator helpers (`filter` / `map` / `take` / `drop` / `reduce` / `toArray`) on generators and `Iterator.from(array)`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const nums: number[] = [];
|
|
5
|
-
for (let i = 0; i < 2048; i++) nums.push((i * 37) & 1023);
|
|
6
|
-
|
|
7
|
-
function* naturals(): Generator<number> {
|
|
8
|
-
let n = 0;
|
|
9
|
-
while (true) yield n++;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function* words(count: number): Generator<string> {
|
|
13
|
-
for (let i = 0; i < count; i++) yield `w${i}`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const start = performance.now();
|
|
17
|
-
let total = 0;
|
|
18
|
-
for (let pass = 0; pass < 900; pass++) {
|
|
19
|
-
const picked = Iterator.from(nums)
|
|
20
|
-
.filter((n) => (n & 3) === (pass & 3))
|
|
21
|
-
.map((n) => n * 2)
|
|
22
|
-
.take(256)
|
|
23
|
-
.toArray();
|
|
24
|
-
total += picked.length + picked[pass & 127];
|
|
25
|
-
total += Iterator.from(nums).drop(1024).reduce((a, n) => a + (n & 7), 0);
|
|
26
|
-
total += words(512)
|
|
27
|
-
.filter((w) => w.length === 3)
|
|
28
|
-
.map((w) => w.charCodeAt(1))
|
|
29
|
-
.reduce((a, c) => a + c, 0);
|
|
30
|
-
total += naturals()
|
|
31
|
-
.map((n) => n & 15)
|
|
32
|
-
.take(512)
|
|
33
|
-
.reduce((a, n) => a + n, 0);
|
|
34
|
-
}
|
|
35
|
-
const elapsed = performance.now() - start;
|
|
36
|
-
|
|
37
|
-
console.log(`checksum: ${total}`);
|
|
38
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
package/performance/json-any.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// perf: `JSON.parse` into `any` and walking the result, `JSON.stringify` of objects built as `any`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const items: any[] = [];
|
|
5
|
-
for (let i = 0; i < 2000; i++) {
|
|
6
|
-
const item: any = { id: i, name: `item ${i}`, ok: (i & 1) === 0, tags: ['a', 'b', `t${i & 7}`] };
|
|
7
|
-
if ((i & 3) === 0) item.extra = { depth: i & 15, note: null };
|
|
8
|
-
items.push(item);
|
|
9
|
-
}
|
|
10
|
-
const text = JSON.stringify({ count: items.length, items });
|
|
11
|
-
|
|
12
|
-
const start = performance.now();
|
|
13
|
-
let total = 0;
|
|
14
|
-
for (let pass = 0; pass < 180; pass++) {
|
|
15
|
-
const doc: any = JSON.parse(text);
|
|
16
|
-
const list: any[] = doc.items;
|
|
17
|
-
for (let i = 0; i < list.length; i++) {
|
|
18
|
-
const it = list[i];
|
|
19
|
-
total += it.id & 7;
|
|
20
|
-
total += it.tags.length;
|
|
21
|
-
if (it.ok) total++;
|
|
22
|
-
if (it.extra) total += it.extra.depth;
|
|
23
|
-
}
|
|
24
|
-
const out: any = { pass, first: list[pass], size: doc.count };
|
|
25
|
-
total += JSON.stringify(out).length + JSON.stringify(list.slice(0, 200)).length;
|
|
26
|
-
}
|
|
27
|
-
const elapsed = performance.now() - start;
|
|
28
|
-
|
|
29
|
-
console.log(`checksum: ${total}`);
|
|
30
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// perf: `JSON.stringify` and `JSON.parse` of an array of nested objects
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
interface Item {
|
|
5
|
-
id: number;
|
|
6
|
-
name: string;
|
|
7
|
-
price: number;
|
|
8
|
-
tags: string[];
|
|
9
|
-
dims: { w: number; h: number };
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const items: Item[] = [];
|
|
13
|
-
for (let i = 0; i < 5000; i++) {
|
|
14
|
-
items.push({ id: i, name: `item "${i}"`, price: i * 1.25, tags: ['x', 'y' + (i % 9)], dims: { w: i % 50, h: 3 } });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const start = performance.now();
|
|
18
|
-
let total = 0;
|
|
19
|
-
for (let pass = 0; pass < 20; pass++) {
|
|
20
|
-
const text = JSON.stringify(items);
|
|
21
|
-
const back = JSON.parse(text) as Item[];
|
|
22
|
-
total += text.length + back.length + back[pass].dims.w;
|
|
23
|
-
}
|
|
24
|
-
const elapsed = performance.now() - start;
|
|
25
|
-
|
|
26
|
-
console.log(`checksum: ${total}`);
|
|
27
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// perf: `Map<string, number>` insert/delete churn (an LRU-style sliding window)
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const keys: string[] = [];
|
|
5
|
-
for (let i = 0; i < 4096; i++) keys.push(`key-${i}`);
|
|
6
|
-
const window = 2048;
|
|
7
|
-
const n = 1_000_000;
|
|
8
|
-
|
|
9
|
-
const start = performance.now();
|
|
10
|
-
const m = new Map<string, number>();
|
|
11
|
-
let total = 0;
|
|
12
|
-
for (let i = 0; i < n; i++) {
|
|
13
|
-
m.set(keys[i & 4095], i);
|
|
14
|
-
if (i >= window) {
|
|
15
|
-
const old = keys[(i - window) & 4095];
|
|
16
|
-
if (m.delete(old)) total++;
|
|
17
|
-
}
|
|
18
|
-
if (m.has(keys[(i * 7) & 4095])) total += 2;
|
|
19
|
-
}
|
|
20
|
-
for (const [, v] of m) total += v & 15;
|
|
21
|
-
const elapsed = performance.now() - start;
|
|
22
|
-
|
|
23
|
-
console.log(`checksum: ${total * 10 + m.size}`);
|
|
24
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// perf: iterating a `Map` (`for…of` entries, `forEach`, `[...values()]`), also after deletes
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const map = new Map<string, number>();
|
|
5
|
-
for (let i = 0; i < 4096; i++) map.set(`k${i}`, i);
|
|
6
|
-
|
|
7
|
-
const start = performance.now();
|
|
8
|
-
let total = 0;
|
|
9
|
-
for (let pass = 0; pass < 900; pass++) {
|
|
10
|
-
for (const [k, v] of map) total += k.length + v;
|
|
11
|
-
map.forEach((v, k) => {
|
|
12
|
-
total += v & 7;
|
|
13
|
-
});
|
|
14
|
-
const values = [...map.values()];
|
|
15
|
-
total += values.length + values[pass];
|
|
16
|
-
for (const k of map.keys()) total += k.length;
|
|
17
|
-
// churn a few keys so iteration sees dead slots
|
|
18
|
-
const victim = `k${(pass * 37) & 4095}`;
|
|
19
|
-
const v = map.get(victim) ?? 0;
|
|
20
|
-
map.delete(victim);
|
|
21
|
-
map.set(victim, v);
|
|
22
|
-
}
|
|
23
|
-
const elapsed = performance.now() - start;
|
|
24
|
-
|
|
25
|
-
console.log(`checksum: ${total}`);
|
|
26
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// perf: `Map<number, T>` lookups by integer id and memoization
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
class Entity {
|
|
5
|
-
id: number;
|
|
6
|
-
score: number;
|
|
7
|
-
constructor(id: number) {
|
|
8
|
-
this.id = id;
|
|
9
|
-
this.score = id & 31;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const byId = new Map<number, Entity>();
|
|
14
|
-
for (let i = 0; i < 8192; i++) byId.set(i * 3, new Entity(i * 3));
|
|
15
|
-
|
|
16
|
-
const memo = new Map<number, number>();
|
|
17
|
-
function collatz(n: number): number {
|
|
18
|
-
if (n === 1) return 0;
|
|
19
|
-
const hit = memo.get(n);
|
|
20
|
-
if (hit !== undefined) return hit;
|
|
21
|
-
const steps = 1 + collatz((n & 1) === 0 ? n / 2 : 3 * n + 1);
|
|
22
|
-
memo.set(n, steps);
|
|
23
|
-
return steps;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const start = performance.now();
|
|
27
|
-
let total = 0;
|
|
28
|
-
for (let i = 0; i < 3_000_000; i++) {
|
|
29
|
-
const e = byId.get((i * 7) & 32767);
|
|
30
|
-
if (e) total += e.score;
|
|
31
|
-
if (byId.has(i & 1023)) total++;
|
|
32
|
-
}
|
|
33
|
-
for (let n = 1; n < 200_000; n++) total += collatz(n);
|
|
34
|
-
const elapsed = performance.now() - start;
|
|
35
|
-
|
|
36
|
-
console.log(`checksum: ${total}`);
|
|
37
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// perf: `Map<string, number>` `set` / `get` / `has` word counting
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const keys: string[] = [];
|
|
5
|
-
for (let i = 0; i < 50_000; i++) keys.push('word' + ((i * 7) % 20_000));
|
|
6
|
-
|
|
7
|
-
const start = performance.now();
|
|
8
|
-
let hits = 0;
|
|
9
|
-
for (let pass = 0; pass < 30; pass++) {
|
|
10
|
-
const counts = new Map<string, number>();
|
|
11
|
-
for (const k of keys) {
|
|
12
|
-
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < 25_000; i++) {
|
|
15
|
-
if (counts.has('word' + i)) hits++;
|
|
16
|
-
}
|
|
17
|
-
hits += counts.size;
|
|
18
|
-
}
|
|
19
|
-
const elapsed = performance.now() - start;
|
|
20
|
-
|
|
21
|
-
console.log(`checksum: ${hits}`);
|
|
22
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// perf: tight float64 loop with `%`, `*` and `Math.floor`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const n = 50_000_000;
|
|
5
|
-
|
|
6
|
-
const start = performance.now();
|
|
7
|
-
let sum = 0;
|
|
8
|
-
for (let i = 0; i < n; i++) {
|
|
9
|
-
sum += Math.floor((i * 31) / 7) % 13;
|
|
10
|
-
}
|
|
11
|
-
const elapsed = performance.now() - start;
|
|
12
|
-
|
|
13
|
-
console.log(`checksum: ${sum}`);
|
|
14
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// perf: bitwise and, or, xor and shifts (`<<`, `>>`, `>>>`) on integers, and flag tests
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const F_A = 1 << 0;
|
|
5
|
-
const F_B = 1 << 3;
|
|
6
|
-
const F_C = 1 << 7;
|
|
7
|
-
const n = 20_000_000;
|
|
8
|
-
|
|
9
|
-
const start = performance.now();
|
|
10
|
-
let acc = 0;
|
|
11
|
-
let hits = 0;
|
|
12
|
-
for (let i = 0; i < n; i++) {
|
|
13
|
-
const flags = (i ^ (i >> 3)) & 0xff;
|
|
14
|
-
if ((flags & F_A) !== 0) hits++;
|
|
15
|
-
if ((flags & (F_B | F_C)) === F_B) hits += 2;
|
|
16
|
-
acc = (acc + ((i << 2) | (flags >>> 1))) & 0xffffff;
|
|
17
|
-
}
|
|
18
|
-
const elapsed = performance.now() - start;
|
|
19
|
-
|
|
20
|
-
console.log(`checksum: ${acc * 1000 + hits}`);
|
|
21
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// perf: FNV-1a and murmur-style string hashing with `Math.imul`, `>>> 0` and `charCodeAt`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
function fnv1a(s: string): number {
|
|
5
|
-
let h = 0x811c9dc5;
|
|
6
|
-
for (let i = 0; i < s.length; i++) {
|
|
7
|
-
h ^= s.charCodeAt(i);
|
|
8
|
-
h = Math.imul(h, 0x01000193);
|
|
9
|
-
}
|
|
10
|
-
return h >>> 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function mix(h: number): number {
|
|
14
|
-
h ^= h >>> 16;
|
|
15
|
-
h = Math.imul(h, 0x85ebca6b);
|
|
16
|
-
h ^= h >>> 13;
|
|
17
|
-
h = Math.imul(h, 0xc2b2ae35);
|
|
18
|
-
h ^= h >>> 16;
|
|
19
|
-
return h >>> 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const keys: string[] = [];
|
|
23
|
-
for (let i = 0; i < 1024; i++) keys.push(`key-${i}-${(i * 2654435761) >>> 20}`);
|
|
24
|
-
|
|
25
|
-
const start = performance.now();
|
|
26
|
-
let total = 0;
|
|
27
|
-
for (let pass = 0; pass < 4500; pass++) {
|
|
28
|
-
for (let i = 0; i < keys.length; i++) {
|
|
29
|
-
const h = mix(fnv1a(keys[i]) + pass);
|
|
30
|
-
total += h & 1023;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const elapsed = performance.now() - start;
|
|
34
|
-
|
|
35
|
-
console.log(`checksum: ${total}`);
|
|
36
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// perf: `%` on integer operands (hash buckets, cycling indexes)
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const n = 20_000_000;
|
|
5
|
-
|
|
6
|
-
const start = performance.now();
|
|
7
|
-
let sum = 0;
|
|
8
|
-
let k = 7;
|
|
9
|
-
for (let i = 0; i < n; i++) {
|
|
10
|
-
sum += (i * 31 + k) % 1009;
|
|
11
|
-
k = (k + i) % 97;
|
|
12
|
-
}
|
|
13
|
-
const elapsed = performance.now() - start;
|
|
14
|
-
|
|
15
|
-
console.log(`checksum: ${sum}`);
|
|
16
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// perf: number/string conversion: `String(n)`, `toFixed`, `Number(str)`, `parseInt`
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
|
|
4
|
-
const n = 1_000_000;
|
|
5
|
-
|
|
6
|
-
const start = performance.now();
|
|
7
|
-
let sum = 0;
|
|
8
|
-
for (let i = 0; i < n; i++) {
|
|
9
|
-
const s = String(i * 3);
|
|
10
|
-
const f = (i / 8).toFixed(2);
|
|
11
|
-
sum += s.length + f.length + Number(s) + parseInt(f, 10);
|
|
12
|
-
}
|
|
13
|
-
const elapsed = performance.now() - start;
|
|
14
|
-
|
|
15
|
-
console.log(`checksum: ${sum}`);
|
|
16
|
-
console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
|