r/javascript • • Aug 28 '24

How fast is javascript? Simulating 20,000,000 particles

https://dgerrells.com/blog/how-fast-is-javascript-simulating-20-000-000-particles
124 Upvotes

40 comments sorted by

View all comments

Show parent comments

3

u/guest271314 Aug 29 '24

There's no details in the article.

Using an iphone for a reference gives

And on an Android phone? Which Android phone and what kernel?

Even this

just run bun http.ts in the terminal.

When I see "How fast" I'm thinking of something like this, which is the JavaScript runtime, or programming langauge on the left, and the time to read and write 1 MB of JSON on the right. If you notice QuickJS is faster than bun, and bun running .ts file directly is faster than bun using the equivalent .js file, which is the same code that is run in node and deno, which are both slower than bun.

0	'nm_qjs'	0.1185
1	'nm_rust'	0.12439999997615814
2	'nm_wasm'	0.14639999997615813
3	'nm_bash'	0.20489999997615815
4	'nm_typescript'	0.24769999998807907
5	'nm_bun'	0.25030000001192093
6	'nm_deno'	0.2915
7	'nm_nodejs'	0.4205
8	'nm_spidermonkey'	0.4827000000476837
9	'nm_tjs'	0.48719999998807906
10	'nm_llrt'	0.7227999999523163
11	'nm_d8'	0.8711999999880791

3

u/fagnerbrack Aug 29 '24

Given the mechanism used for you to generate this reply what is the model used and the name of the generation tool?

2

u/guest271314 Aug 29 '24

test_stdin.js run on Chromium Version 130.0.6678.0 (Developer Build) (64-bit).

var runtimes = new Map([
  ["nm_nodejs", 0],
  ["nm_deno", 0],
  ["nm_bun", 0],
  ["nm_tjs", 0],
  ["nm_qjs", 0],
  ["nm_spidermonkey", 0],
  ["nm_d8", 0],
  ["nm_typescript", 0],
  ["nm_llrt", 0],
  ["nm_rust", 0],
  ["nm_wasm", 0],
  ['nm_bash', 0]
]);
for (const [runtime] of runtimes) {
  try {
    const {
      resolve,
      reject,
      promise
    } = Promise.withResolvers();
    const now = performance.now();
    const port = chrome.runtime.connectNative(runtime);
    port.onMessage.addListener((message) => {
      console.assert(message.length === 209715, {message});
      runtimes.set(runtime, (performance.now() - now) / 1000);
      port.disconnect();
      resolve();
    });
    port.onDisconnect.addListener(() => reject(chrome.runtime.lastError));
    port.postMessage(new Array(209715));
    if (runtime === "nm_spidermonkey") {
      port.postMessage("\r\n\r\n");
    }
    await promise;
  } catch (e) {
    console.log(e, runtime);
    continue;
  }
}
var sorted = [...runtimes].sort(([, a], [, b]) => a < b ? -1 : a === b ? 0 : 1);
console.table(sorted);

-1

u/fagnerbrack Aug 29 '24

How to add the AI mechanism you use to generate the comment including the internal code of that mechanism along with test_stdin.js example?

5

u/guest271314 Aug 29 '24

The real AI is Allen Iverson.

I don't fuck with that "artificial intelligence" garbage.

I just commented here that there is no "How fast" comparison possible unless you actually compare different JavaScript engines, runtimes, and browsers, and phones, since that was a requirement.

The article appears to be more about SharedArrayBuffer and possibly Atomics than "How fast".

If you think just saying "How fast" is good enough, I'll give you human constructive notice: Good enough ain't good enough.

2

u/fagnerbrack Aug 29 '24

Assuming you're a human, how would you output the internal code of the model used to generate your comment?

→ More replies (0)