-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
56 lines (43 loc) · 2.16 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
if (/qnit/.test(process.argv[1])) return;
// npm install qtimeit uuid node-uuid hyperid mongoid-js fast-uuid
var qtimeit = require('qtimeit');
var uuidquick = require('./');
var getId = require('../qibl').makeGetId('-test-');
// require but guard against parse errors
function tryRequire(path) { try { return require(path) } catch (e) { return {} } }
var uuid = require('uuid').v4;
var nodeuuid = require('node-uuid').v4;
var fastuuid = tryRequire('fast-uuid').uuid4;
//var hyperidModule = require('hyperid');
//var hyperid = hyperidModule({ fixedLength: true });
//var shortid = require('shortid').generate;
//var nanoid = require('nanoid');
var mongoidjs = require('mongoid-js');
//var _140byte_uuid = function(){return(""+1e7+-1e3+-4e3+-8e3+-1e11).replace(/1|0/g,function(){return(0|Math.random()*16).toString(16)})};
var x, x2;
var mongoidFactory = new mongoidjs.MongoId();
qtimeit.bench.timeGoal = .15;
qtimeit.bench.showRunDetails = false;
qtimeit.bench.visualize = true;
qtimeit.bench.bargraphScale = 2;
qtimeit.bench.opsPerTest = 2;
var bench = {};
if (uuid) bench['uuid'] = function() { x = uuid(); x2 = uuid() };
if (nodeuuid) bench['node-uuid'] = function() { x = nodeuuid(); x2 = nodeuuid() };
if (fastuuid) bench['fast-uuid'] = function() { x = fastuuid(); x2 = fastuuid() };
if (uuidquick) bench['uuid-quick'] = function() { x = uuidquick(); x2 = uuidquick() };
// if (getId) bench['qibl.getId'] = function() { x = getId(); x2 = getId() };
// other ids
//'shortid': function() { x = shortid(); x2 = shortid() }, // very slow
//'nanoid': function() { x = nanoid(); x2 = nanoid() },
//'hyperid': function() { x = hyperid(); x2 = hyperid() }, // not a uuid, is fixed uuid+counter
qtimeit.bench(bench);
qtimeit.bench.timeGoal = .15;
qtimeit.bench({
'uuid-quick': function() { x = uuidquick(); x2 = uuidquick() },
//'mongoid-js': function() { x = mongoidjs(); x2 = mongoidjs() },
//'mongoid-js': function() { x = mongoidFactory.fetch(); x2 = mongoidFactory.fetch() },
'mongoid-js short': function() { x = mongoidFactory.fetchShort(); x2 = mongoidFactory.fetchShort() },
'qibl.getId': function() { x = getId(); x2 = getId() },
});
console.log("AR: q-id =", x);