-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
74 lines (66 loc) · 3.71 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var Benchmark = require('benchmark')
// ignore the lines with arb, it's not just the slowest by two orders of magnitude, but given how it is written, it SHOULD be the slowest
var arb = require('./arb-tests.js')()
var biginteger = require('./biginteger-tests.js')()
var BigInt = require('./bigint-tests.js')()
var bn = require('./bn-tests.js')()
var mathjs = require('./mathjs-tests.js')()
var asmbn = require('./asmbignum-tests.js')()
// Benchmark.options.minTime = 1
// Benchmark.options.minSamples = 50
// add tests
//var addition = new Benchmark.Suite
//addition.add('arb-add', arb.addition, {onCycle: arb.clean})
//addition.add('biginteger-add', biginteger.addition, {onCycle: biginteger.clean})
//addition.add('BigInt-add', BigInt.addition, {onCycle: BigInt.clean})
//addition.add('bn-add', bn.addition, {onCycle: bn.clean})
//addition.add('mathjs-add', mathjs.addition, {onCycle: mathjs.clean})
//addition.add('asmbn-add', asmbn.addition, {onCycle: asmbn.clean})
//
//// add listeners
//addition.on('error', function(event) { console.log( 'err', event) })
//addition.on('cycle', function(event) { console.log(String(event.target)) })
//addition.on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')) })
//// run async
//addition.run({ 'async': false })
// var subtraction = new Benchmark.Suite
// subtraction.add('arb-subtraction', arb.subtraction, {onCycle: arb.clean})
// subtraction.add('biginteger-subtraction', biginteger.subtraction, {onCycle: biginteger.clean})
// subtraction.add('BigInt-subtraction', BigInt.subtraction, {onCycle: BigInt.clean})
// subtraction.add('bn-subtraction', bn.subtraction, {onCycle: bn.clean})
// subtraction.add('mathjs-subtraction', mathjs.subtraction, {onCycle: mathjs.clean})
// subtraction.add('asmbn-add', asmbn.subtraction, {onCycle: asmbn.clean})
//
// // add listeners
// subtraction.on('cycle', function(event) { console.log(String(event.target)) })
// subtraction.on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')) })
// // run async
// subtraction.run({ 'async': false })
var multiplication = new Benchmark.Suite
multiplication.add('arb-multiplication', arb.multiplication, {onCycle: arb.clean})
multiplication.add('biginteger-multiplication', biginteger.multiplication, {onCycle: biginteger.clean})
multiplication.add('BigInt-multiplication', BigInt.multiplication, {onCycle: BigInt.clean})
multiplication.add('bn-multiplication', bn.multiplication, {onCycle: bn.clean})
multiplication.add('mathjs-multiplication', mathjs.multiplication, {onCycle: mathjs.clean})
multiplication.add('asmbn-multiplication', asmbn.multiplication, {onCycle: asmbn.clean})
// add listeners
multiplication.on('cycle', function(event) { console.log(String(event.target)) })
multiplication.on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')) })
// run async
multiplication.run({ 'async': false })
//
//
//var division = new Benchmark.Suite
//division.add('arb-division', arb.division, {onCycle: arb.cleanDiv})
//division.add('biginteger-division', biginteger.division, {onCycle: biginteger.clean})
//division.add('BigInt-division', BigInt.division, {onCycle: BigInt.clean})
//division.add('bn-division', bn.division, {onCycle: bn.clean})
//division.add('mathjs-division', mathjs.division, {onCycle: mathjs.clean})
//division.add('asmbn-division', asmbn.division, {onCycle: asmbn.clean})
//
//// add listeners
//division.on('error', function(event) { console.log( 'err', event) })
//division.on('cycle', function(event) { console.log( 'wt', event);console.log(String(event.target)) })
//division.on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')) })
//// run async
//division.run({ 'async': false })