-
Notifications
You must be signed in to change notification settings - Fork 26
/
property-removal.js
64 lines (46 loc) · 1.29 KB
/
property-removal.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
'use strict'
var benchmark = require('benchmark')
var suite = new benchmark.Suite()
function MyClass (x, y) {
this.x = x
this.y = y
}
function MyClassLast (x, y) {
this.y = y
this.x = x
}
// You can tell if an object is in hash table mode by calling console.log(%HasFastProperties(obj)) when the flag --allow-natives-syntax is enabled in Node.JS.
// you can convert back to fast properties using
// https://www.npmjs.com/package/to-fast-properties
suite.add('setting to undefined', function undefProp () {
var obj = new MyClass(2, 3)
obj.x = undefined
JSON.stringify(obj)
})
suite.add('delete', function deleteProp () {
var obj = new MyClass(2, 3)
delete obj.x
JSON.stringify(obj)
})
suite.add('delete last property', function deleteProp () {
var obj = new MyClassLast(2, 3)
delete obj.x
JSON.stringify(obj)
})
suite.add('setting to undefined literal', function undefPropLit () {
var obj = { x: 2, y: 3 }
obj.x = undefined
JSON.stringify(obj)
})
suite.add('delete property literal', function deletePropLit () {
var obj = { x: 2, y: 3 }
delete obj.x
JSON.stringify(obj)
})
suite.add('delete last property literal', function deletePropLit () {
var obj = { y: 3, x: 2 }
delete obj.x
JSON.stringify(obj)
})
suite.on('complete', require('./print'))
suite.run()