josdejong / typed-function

Runtime type-checking for JavaScript functions
MIT License
71 stars 19 forks source link

Extend the benchmark section #146

Closed josdejong closed 2 years ago

josdejong commented 2 years ago

I extended the benchmark section to compare creating/executing of typed functions with varying number of signatures, conversions, params. This can be used compare for regressions/improvements when implementing new features or refactoring stuff.

Example output:

> node .\benchmark\benchmark.js
execute: vanillaAdd                      x 28,583,317 ops/sec ±2.69% (92 runs sampled)
execute: typedAdd                        x 27,209,671 ops/sec ±0.29% (93 runs sampled)
execute:  1 signature,   0 conversions   x 29,603,229 ops/sec ±0.42% (93 runs sampled)
execute: 10 signatures,  0 conversions   x 28,929,622 ops/sec ±2.18% (93 runs sampled)
execute:  1 signatures, 10 conversions   x 10,351,809 ops/sec ±0.40% (96 runs sampled)
execute: 10 signatures, 10 conversions   x 4,610,580 ops/sec ±0.28% (93 runs sampled)
execute:  1 signature,  20 params        x 997,103 ops/sec ±0.46% (95 runs sampled)
create:   1 signature,   0 conversions   x 193,731 ops/sec ±0.65% (93 runs sampled)
create:  10 signatures,  0 conversions   x 22,061 ops/sec ±0.90% (91 runs sampled)
create:   1 signatures, 10 conversions   x 60,337 ops/sec ±1.35% (91 runs sampled)
create:  10 signatures, 10 conversions   x 4,957 ops/sec ±0.34% (94 runs sampled)
create:   1 signature,  20 params        x 30,263 ops/sec ±0.45% (95 runs sampled)

@gwhitney can you have a look at this PR? Feel free to merge it right away in develop. And feel free to make further improvements if needed.

gwhitney commented 2 years ago

Looks reasonable to me. I just added the typed-function creation count stuff as that will be necessary for interpreting future mathjs benchmarks, so it seemed appropriate here. Will merge and then further validate these benchmarks by trying them on the version of "prefer conversion to any" that showed a slowdown in mathjs "load all".

josdejong commented 2 years ago

👍