-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance_test.js
More file actions
51 lines (42 loc) · 954 Bytes
/
Copy pathperformance_test.js
File metadata and controls
51 lines (42 loc) · 954 Bytes
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
class TypeA {
constructor() {
}
}
class TypeB {
constructor() {
}
}
class TypeC {
constructor() {
}
}
class MyType {
constructor(a, b, c) {
this._a = a;
this._b = b;
this._c = c;
}
}
function createObject(Type, arr) {
if (arr.length == 4) return new Type(arr[1], arr[2], arr[3]);
}
for (var j = 0; j < 20; j++) {
console.time('dynamically apply-ing');
for (var i = 0; i < 1000000; i++) {
let a = [null];
a.push(new TypeA());
a.push(new TypeB());
a.push(new TypeC());
let myTypeObj = new (Function.prototype.bind.apply(MyType, a));
}
console.timeEnd('dynamically apply-ing');
console.time('hard-coded calling');
for (var i = 0; i < 1000000; i++) {
let a = [null];
a.push(new TypeA());
a.push(new TypeB());
a.push(new TypeC());
let myTypeObj = createObject(MyType, a);
}
console.timeEnd('hard-coded calling');
}