Add browserify support.
The following code fails using the npm package with Browserify:
var benchmark = require('benchmark')
var suite = benchmark.Suite()
With the following error:
Uncaught TypeError: benchmark.Suite is not a constructor
You can quickly see it happening if you use RequireBin and paste the above code.
Hi @feross!
I believe that means lodash isn't being loaded properly.
@jdalton This was a fresh npm install, and I can confirm that lodash is in the node_modules folder.
Ah ok. Let me know if https://github.com/bestiejs/benchmark.js/commit/7de5705328ec29afa14e8813498e9c6c2a97c0f4 or https://github.com/bestiejs/benchmark.js/commit/c588a6bc349986cfb758486c0b04e8ee256a5ebb helps.
Yep, works better.
Getting errors on this line
(program):1 Uncaught ReferenceError: Benchmark is not defined
But it doesn't seem to be preventing things from working. It's just spewing in the console at the moment.
I'll keep digging.
Using Webpack + Babel for my client-side. This thread was helpful and this is what I ended up with that works for me:
// package.json
"dependencies": {
"benchmark": "^2.1.3",
"lodash": "^4.17.4",
}
// webpack.config.js
...
module: {
noParse: [
/benchmark/,
]
},
...
import _ from 'lodash';
import process from 'process';
const benchmark = require('benchmark');
const Benchmark = benchmark.runInContext({ _, process });
window.Benchmark = Benchmark;
Seems like the noParse was important.
Thanks @julianvmodesto !
Result from piping browserify output to chrome headless.
> browserify --bare ./test/perf.js | tape-run
TypeError: Cannot read property 'parentNode' of undefined
at runScript (http://localhost:52210/bundle.js:902:27)
at createFunction (http://localhost:52210/bundle.js:755:9)
at createFunction (http://localhost:52210/bundle.js:762:44)
at createCompiled (http://localhost:52210/bundle.js:1952:23)
at clock (http://localhost:52210/bundle.js:1846:58)
at clock (http://localhost:52210/bundle.js:2056:20)
at cycle (http://localhost:52210/bundle.js:2245:49)
at Benchmark.run (http://localhost:52210/bundle.js:2352:13)
at execute (http://localhost:52210/bundle.js:1098:74)
at invoke (http://localhost:52210/bundle.js:1208:20)
This issue is caused by the assumption that there will be a script tag in the page (in some cases this is not true)... https://github.com/bestiejs/benchmark.js/blob/c588a6bc349986cfb758486c0b04e8ee256a5ebb/benchmark.js#L663
I am getting the same kind of issue when using Rollup, more info in #244