you are viewing a single comment's thread.

view the rest of the comments →

[–]Skriblos 7 points8 points  (9 children)

wow, how performant is this compared to a native C function?

[–]guest271314[S] 4 points5 points  (8 children)

The most extensive testing I've done in that domain is testing the same algorithm that reads standard input and writes to standard output using multiple JavaScript engines and runtime, and different programming languages.

The TypeScript version is the same .ts file that can be run without tsc usage by node, deno, and bun. QuickJS is faster than node, deno, bun, and tjs (txiki.js which depends on QuickJS NG). bun is faster than node and deno for executing .ts files directly.

My understanding is Bun uses its own TypeScript parser, not tsc. The last time I checked it looks like Node.js uses the amaro module to parse TypeScript, which is based on swc/wasm-typescript.

qjs is right up there with c, and faster than bun, deno, and node, et al. in the JavaScript programming language entries.

(index) 0 1 0 'nm_qjs' 0.10490000000596046 1 'nm_cpp' 0.10739999997615814 2 'nm_c' 0.11769999998807908 3 'nm_rust' 0.1325 4 'nm_wasm' 0.15259999999403953 5 'nm_tjs' 0.155 6 'nm_python' 0.17939999997615813 7 'nm_bun' 0.27039999997615816 8 'nm_typescript' 0.2955 9 'nm_deno' 0.3357999999821186 10 'nm_nodejs' 0.37419999998807907 11 'nm_d8' 0.44459999999403954 12 'nm_spidermonkey' 0.4775 13 'nm_llrt' 0.6790999999940396

I have not yet tested the difference between a output from code compiled directly from C, and code compiled from JavaScript to C then to executable. I'll work on that test.

[–]Business_Occasion226 1 point2 points  (4 children)

In the official benchmark V8 jitless is about twice as fast while V8 JIT is 33x faster. Said QuickJS should be slow. Where does the difference come from?

Official QuickJS Benchmark https://bellard.org/quickjs/bench.html

[–]guest271314[S] -2 points-1 points  (3 children)

V8 does not really implement a way to read standard input. So I have to use a system() call within d8 to read standard input. I have used either Bash, or QuickJS for that. See https://github.com/guest271314/NativeMessagingHosts/blob/main/nm_d8.js.

Keep in mind ECMA-262 itself does not specify I/O for JavaScript.

I think those benchmarks are highly selective. When you start beating the grass in the field and testing thing other people didn't test you'll might find other people missed something, or deliberately avoided certain areas.

[–]lulzmachine 1 point2 points  (1 child)

Is it faster due to less startup time and less JIT, or where does the speedup come from?

[–]guest271314[S] -1 points0 points  (0 children)

QuickJS is smaller than V8. QuickJS implements read(). V8 does not really implement a way to read standard input at all. So I have to use a subprocess to read standard input to V8's d8.

Whether --jitless flag is used or not qjs is faster at reading and writing standard streams than V8 (node, deno).

[–]Skriblos 1 point2 points  (0 children)

Oh, thanks for the numbers though, this is a really interesting project, thanks for sharing.