Skip to content

Commit

Permalink
benchmarks: use process.hrtime() to measure time
Browse files Browse the repository at this point in the history
Use process.hrtime() to measure elapsed time in benchmarks more
accurately.
  • Loading branch information
pmed authored and indutny committed Jun 16, 2016
1 parent 636bb4e commit 9fd7fa8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bench/py.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const obj = JSON.stringify(deep(5));

const COUNT = 1e3;

const start = +new Date;
const start = process.hrtime();
for (let i = 0; i < COUNT; i++)
py.parseJSON(obj);
const end = +new Date;
const end = process.hrtime(start);
const elapsed_seconds = (end[0] * 10e9 + end[1]) / 10e9;

console.log('%d parseJSON ops/sec', COUNT / (end - start) * 1000);
console.log('%d parseJSON ops/sec', (COUNT / elapsed_seconds).toFixed(3));

0 comments on commit 9fd7fa8

Please sign in to comment.