-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
71 lines (59 loc) · 1.68 KB
/
test.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
var x, y, z
const X = function() {}
X.prototype.message = function(s) { var mymessage = s + '' }
X.prototype.addition = function(i, j) { return (i *2 + j * 2) / 2 }
const Y = function() {
this.message = function(s) { var mymessage = s + '' }
this.addition = function(i, j) { return (i *2 + j * 2) / 2 }
}
const Z = (
{ message: function(s) { var mymessage = s + ''}
, addition: function(i, j) { return (i *2 + j * 2) / 2 }
}
)
const F = (
{ __proto__: null
, message: function(s) { var mymessage = s + ''}
, addition: function(i, j) { return (i *2 + j * 2) / 2 }
}
)
function test ( name
, construct
, { index = 0, count = 10000 } = {}
) {
var subject = construct()
while(index++ < count) {
}
}
function TestPerformance()
{
var closureStartDateTime = new Date()
for (var i = 0; i < 100000; i++)
{
y = new Y()
y.message('hi')
y.addition(i, 2)
}
var closureEndDateTime = new Date()
var prototypeStartDateTime = new Date()
for (var i = 0; i < 100000; i++)
{
x = new X()
x.message('hi')
x.addition(i, 2)
}
var prototypeEndDateTime = new Date()
var staticObjectStartDateTime = new Date()
for (var i = 0; i < 100000; i++)
{
z = Z // obviously you don't really need this
z.message('hi')
z.addition(i, 2)
}
var staticObjectEndDateTime = new Date()
var closureTime = closureEndDateTime.getTime() - closureStartDateTime.getTime()
var prototypeTime = prototypeEndDateTime.getTime() - prototypeStartDateTime.getTime()
var staticTime = staticObjectEndDateTime.getTime() - staticObjectStartDateTime.getTime()
console.info({ closureTime, prototypeTime, staticTime })
}
TestPerformance()