-
Notifications
You must be signed in to change notification settings - Fork 22
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
Adjust for API differences in bench code #17
Conversation
Codecov Report
@@ Coverage Diff @@
## master #17 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 16 16
Branches 11 11
=====================================
Hits 16 16 Continue to review full report at Codecov.
|
Thanks, @apostolos! Maybe we need to tweak the benchmarks a bit more. Classcat is meant to be used as: cc(["foo", "bar", "baz"]) // => foo bar baz whereas classNames is like: cc("foo", "bar", "baz") // => foo So, it would be great if we could bench each function how they are supposed to be used. |
…in classNames test when args.length==1
I think that's what I'm doing already. You'll notice that before adding a benchmark function to the Suite, I first measure the args[] length:
You'll also notice that I pass different functions for each case to the suite to avoid measuring the args.length check. |
UPDATE: I refactored the code a bit:
That way we avoid any potential object/array lookups when not needed and function calls are always how they are supposed to be used. New bench numbers (on a i7-6500U @ 2.50GHz):
|
@apostolos Okay, I finally a chance to have a look at this and you were totally right! I still think your code can be simplified a bit more, so I'll just take care of it. 😅 I want to rewrite the bench this way instead: suite
.add(`Classcat – ${fixed.description}`, () => cc(fixed.args))
.add(`classNames – ${fixed.description}`, () => cx.apply({}, fixed.args)) |
@apostolos I've updated the benchmarks and added the new (correct) results to #16. Thanks! 👋 |
Benchmark code wrongly applies fixture args on
classcat
. That causes the actual call to be:e.g. for
["one", "two", "three"]
, it currently benchmarks:instead of:
This means the benchmark compares different work parameters for
classcat
andclassNames
.Furthermore, as far as I can tell,
Benchmark.Suite()
does not validate function output. Theexpected
value under ./bench/fixtures.js is ignored that's why this error was easy to miss.This PR adjusts benchmark code to make comparison fair for both functions.
Although
classcat
is still faster thanclassNames
, it is not 5x times faster. The old Strings & Objects benchmark giving such an impossible result should have been a red flag.New results
Node 9.4.0 on an AMD Ryzen 1500X
Old Classcat – Strings × 17,286,017 ops/secActual Classcat – Strings × 7,947,812 ops/sec
classNames – Strings × 4,261,603 ops/sec
Fastest is Old Classcat – StringsFastest is Actual Classcat – Strings
Old Classcat – Objects × 5,754,260 ops/secActual Classcat – Objects × 7,158,794 ops/sec
classNames – Objects × 3,634,329 ops/sec
Fastest is Actual Classcat – Objects
Old Classcat – Strings & Objects × 16,294,161 ops/secActual Classcat – Strings & Objects × 4,732,941 ops/sec
classNames – Strings & Objects × 3,325,816 ops/sec
Fastest is Old Classcat – Strings & ObjectsFastest is Actual Classcat – Strings & Objects
Old Classcat – Mixed × 7,319,186 ops/secActual Classcat – Mixed × 2,645,379 ops/sec
classNames – Mixed × 2,356,888 ops/sec
Fastest is Old Classcat – MixedFastest is Actual Classcat – Mixed
Old Classcat – Arrays × 2,007,313 ops/secActual Classcat – Arrays × 2,254,936 ops/sec
classNames – Arrays × 912,869 ops/sec
Fastest is Actual Classcat – Arrays