-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtry-catch.js
60 lines (45 loc) · 917 Bytes
/
try-catch.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
'use strict'
var benchmark = require('benchmark')
var suite = new benchmark.Suite()
function sum (base, max) {
var total = 0
for (var i = base; i < max; i++) {
total += i
}
}
suite.add('sum with try catch', function sumTryCatch () {
try {
var base = 0
var max = 65535
var total = 0
for (var i = base; i < max; i++) {
total += i
}
} catch (err) {
console.log(err.message)
}
})
suite.add('sum without try catch', function noTryCatch () {
var base = 0
var max = 65535
var total = 0
for (var i = base; i < max; i++) {
total += i
}
})
suite.add('sum wrapped', function wrapped () {
var base = 0
var max = 65535
try {
sum(base, max)
} catch (err) {
console.log(err.message)
}
})
suite.add('sum function', function func () {
var base = 0
var max = 65535
sum(base, max)
})
suite.on('complete', require('./print'))
suite.run()