array-last
array-last copied to clipboard
Performance Boost
Yo~!
This improves performance significantly on any number slicing or parsing. It also defaults any NaN-derived value to 1, the default.
I also included a simple solution to #7.
Custom benchmarks were setup as the current ones seem to be outdated & I couldn't get them to work =/ These were made with benchmark.js and your randomatic lib for fixtures. I can PR this as well if you're interested.
Before
# Last Item (1000)
array-last x 167,157,582 ops/sec ±0.16% (97 runs sampled)
# Last Item (1000000)
array-last x 166,438,057 ops/sec ±0.58% (95 runs sampled)
# Last 10 Items (1000)
array-last x 29,290,764 ops/sec ±0.25% (95 runs sampled)
# Last 10 Items (1000000)
array-last x 29,418,958 ops/sec ±0.28% (96 runs sampled)
# Last "10" Items (1000)
array-last x 17,594,653 ops/sec ±0.76% (98 runs sampled)
# Last "10" Items (1000000)
array-last x 17,747,237 ops/sec ±1.69% (96 runs sampled)
# Last N+1 Items (1000)
array-last x 921 ops/sec ±0.14% (96 runs sampled)
# Last N+1 Items (1000000)
array-last x 74.02 ops/sec ±3.78% (64 runs sampled)
After
# Last Item (1000)
array-last x 167,646,149 ops/sec ±0.18% (95 runs sampled)
# Last Item (1000000)
array-last x 167,290,607 ops/sec ±0.62% (94 runs sampled)
# Last 10 Items (1000)
array-last x 35,060,211 ops/sec ±0.59% (90 runs sampled)
# Last 10 Items (1000000)
array-last x 35,672,206 ops/sec ±0.21% (98 runs sampled)
# Last "10" Items (1000)
array-last x 23,583,987 ops/sec ±0.82% (92 runs sampled)
# Last "10" Items (1000000)
array-last x 23,344,110 ops/sec ±1.93% (98 runs sampled)
# Last N+1 Items (1000)
array-last x 132,743,603 ops/sec ±0.34% (96 runs sampled)
# Last N+1 Items (1000000)
array-last x 132,547,623 ops/sec ±0.62% (95 runs sampled)
I dig this. I think it would be great to have the benchmarks and a test for the fix you added.