akdubya / uubench Goto Github PK
View Code? Open in Web Editor NEWA tiny asynchronous JavaScript benchmarking library
License: MIT License
A tiny asynchronous JavaScript benchmarking library
License: MIT License
hey, im doing
var persec = 1000 / stats.elapsed
, ops = stats.iterations * persec;
where i'd expect setTimeout(next, 1000)
to give 1 op/s, however it seems to be around 10 etc
According to README.md:
var suite = new uubench.Suite({
min: 1000, // each benchmark should run for at least 1000ms
...
});
I looked up the source code:
function adaptive() {
if (--pend === 0) {
var elapsed = new Date() - start;
if (elapsed < min) {
self.run(iter*2);
} else {
self.callback({iterations: iter, elapsed: elapsed});//since "start" is reset whenever "Bench.run" is invoked, then the stats is inaccurate
}
}
}
The key point is that the value of "start" is reset whenever "Bench.run" is invoked:
Bench.prototype.run = function(iter) {
var self = this, fn = self.test,
checkfn = self.options.type === "adaptive" ? adaptive : fixed,
i = iter, pend = i,
min = self.options.min, start;
if (self.loop) {
pend = 1;
start = new Date(); //start is reset
fn(checkfn, i);
} else {
start = new Date(); //start is reset
while (i--) {
fn(checkfn);
}
}
So the stats is inaccurate, I think the value of "start" should be set at the very begining of "Suite.prototype.runOne", and don't reset it in Bench.run:
Suite.prototype.runOne = function(idx) {
var self = this;
setTimeout(function() {
self.tests[idx].start = new Date().getTime(); //set "start" value here, so "min" is the accumulative runtime for benchmark
self.tests[idx].run(self.options.iterations);
}, self.options.delay);
}
I'm very curious to this issue. Please give me a hint!
Finally, many thanks to you for your great work and the sharing :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.