OS X slower than Linux, slower than native for short strings
See original GitHub issueI was benchmarking this library on my laptop and it is more than 2 times slower than native implementation. Is the testing code wrong or the benchmark in readme is wrong.
HW MacBook Pro (15-inch, 2016) 2,7 GHz Intel Core i7 16 GB 2133 MHz LPDDR3
Code
var now = require('performance-now')
var b64 = require('64')
function run (fn, desc) {
var start = now()
for (var i = 0; i < 1000000; i++) {
fn()
}
var end = now()
console.log(desc, (end - start).toFixed(2), 'ms')
}
console.log('NODE', process.version)
run(() => b64.decode(Buffer.from(b64.encode(Buffer.from('test string')), 'base64')), '64')
run(() => Buffer.from(Buffer.from('test string').toString('base64'), 'base64').toString('ascii'), 'native')
Results
NODE v8.1.4
64 2304.52 ms
native 1058.34 ms
NODE v7.6.0
64 2644.51 ms
native 1180.36 ms
NODE v6.10.2
64 2964.18 ms
native 1373.59 ms
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
macOS slower than linux - MacRumors Forums
The performance of Linux seems to depend quite a bit on the desktop environment, but I find them to be quicker than macOS....
Read more >native macOS is how much slower than Linux in a Qemu VM?
We finally got #Qemu on #AppleSilicon Mac, and as expected # Linux compiles software easily 3x faster than natively on #macOS!
Read more >Is it a myth that Macs do not get slower over time like PC?
It's harder to mess up a Mac (or easier to keep it fast) but it will get slower just as a PC when...
Read more >Why are Disk Images so slow at writing?
This article follows that up by evaluating the read and write performance of different types of Disk Image, including those with encryption.
Read more >Why is creating a new process more expensive on Windows ...
Native processes (with no environment subsystem) are very fast to create. SFU does a lot less than Win32 for process creation, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve updated the upstream base64 library to the latest commit and performance is much improved - see https://github.com/lovell/64#performance
OS X (clang) still doesn’t seem to produce quite as efficient code as Linux/Windows but in summary processing Buffers longer than ~300 bytes will benefit from this module.
There is also a threshold for the decision to use this shared library vs Buffer’s own implementation - see https://github.com/lovell/64/blob/master/index.js#L7-L8 - thanks for this idea.
This is available via npm as v0.1.2.
Thanks for reporting this and your help debugging.
Thanks for confirming that
--build-from-source
makes no difference. The OS X discrepancy may be a problem with clang and/or the base64 library code itself.I quite like the idea of implicitly switching implementations based on input size, plus this is where your suggestion of a graph showing input size against performance would help.
In terms of the API accepting strings, we’d need to ensure that the type-detection overhead doesn’t slow things down too much. Happy to accept a PR for this if you’re willing and able 😃