Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can eshost provide cross-implementation benchmarking? #126

Open
gibson042 opened this issue Oct 26, 2022 · 0 comments
Open

Can eshost provide cross-implementation benchmarking? #126

gibson042 opened this issue Oct 26, 2022 · 0 comments

Comments

@gibson042
Copy link
Contributor

I sometimes find the need to compare code variations across implementations, for which eshost is actually a great supporting tool. I've got a script that hard-codes some loop controls and uses Date.now() for measurement, but it would be great to have (more sophisticated) functionality integrated here.

Interface sketch:

$ eshost -h V8,'*XS*' \
  --prelude '/* general option; runs before any expression or statement */
    "use strict";
    const { fromEntries } = Object;
    const { ownKeys } = Reflect;
    const reverseComparator = (left, right) => left < right ? 1 : left === right ? 0 : -1;
    const result;
  ' \
  --benchmark '/* mode switch and code to run before each timed section */
    const str = String.fromCodePoint(i).repeat(1000);
  ' \
  --benchmark--'str[0]' '
    /* named benchmark code */
    /* (`--benchmark--"$name" "$code"` structured option name form) */
    result = str[0];
  ' \
  --benchmark-named 'charAt(0)' '
    /* named benchmark code */
    /* (`--benchmark-named "$name" "$code"` two-argument option form) */
    result = str.charAt(0);
  ' \
  --benchmark-variant '"at(0)" '
    /* (optionally?)named benchmark code */
    /* (`--benchmark-variant "${<<<"$name" jq -R} $code"` space-separated structured option value form) */
    result = str.at(0);
  '
#### Moddable XS
str[0]: 1,445,376 ops/sec ±0.25% (91 runs sampled)
charAt(0): 2,992,670 ops/sec ±0.55% (85 runs sampled)
str.at(0): 1,417,580 ops/sec ±0.71% (90 runs sampled)

#### V8
str[0]: 225,206,729 ops/sec ±0.25% (91 runs sampled)
charAt(0): 138,581,640 ops/sec ±0.55% (85 runs sampled)
at(0): 62,485,375 ops/sec ±0.71% (90 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant