1
1
var Benchmark = require ( 'benchmark' ) ;
2
2
3
+ function Node ( k , v , p , l , r ) {
4
+ this . k = k ;
5
+ this . v = v ;
6
+ this . p = p ;
7
+ this . l = l ;
8
+ this . r = r ;
9
+ }
10
+
3
11
var array = {
4
12
parent : [ 'some_key' , 1234123412 , null , null , null ] ,
5
13
left : [ 'left_child' , 'asdfoasjdfpasdjf' , null , null , null ] ,
@@ -36,6 +44,12 @@ var objectS = {
36
44
right : { k : 'right child' , v : 'qwerqwerqwerqwwq' , p : null , l : null , r : null }
37
45
} ;
38
46
47
+ var objectC = {
48
+ parent : new Node ( 'some_key' , 1234123412 , null , null , null ) ,
49
+ left : new Node ( 'left_child' , 'asdfoasjdfpasdjf' , null , null , null ) ,
50
+ right : new Node ( 'right_child' , 'qwerqwerqwerqwwq' , null , null , null )
51
+ } ;
52
+
39
53
new Benchmark . Suite ( )
40
54
. add ( 'Object node manipulation' , function ( ) {
41
55
var temp = object . parent ;
@@ -57,7 +71,7 @@ new Benchmark.Suite()
57
71
object . right . right = null ;
58
72
} )
59
73
. add ( 'Object node manipulation - small key' , function ( ) {
60
- var temp = objectS . parent ;
74
+ var temp = objectS . parent ;
61
75
objectS . parent = objectS . left ;
62
76
objectS . left = objectS . right ;
63
77
objectS . right = temp ;
@@ -75,6 +89,25 @@ new Benchmark.Suite()
75
89
objectS . right . l = null ;
76
90
objectS . right . r = null ;
77
91
} )
92
+ . add ( 'Class node manipulation' , function ( ) {
93
+ var temp = objectC . parent ;
94
+ objectC . parent = objectC . left ;
95
+ objectC . left = objectC . right ;
96
+ objectC . right = temp ;
97
+
98
+ objectC . parent . p = null ;
99
+ objectC . parent . l = objectC . left ;
100
+ objectC . parent . r = objectC . right ;
101
+
102
+
103
+ objectC . left . p = objectC . parent ;
104
+ objectC . left . l = null ;
105
+ objectC . left . r = null ;
106
+
107
+ objectC . right . p = objectC . parent ;
108
+ objectC . right . l = null ;
109
+ objectC . right . r = null ;
110
+ } )
78
111
. add ( 'Array node manipulation' , function ( ) {
79
112
var temp = array . parent ;
80
113
array . parent = array . left ;
@@ -97,6 +130,7 @@ new Benchmark.Suite()
97
130
console . log ( this [ 0 ] . toString ( ) ) ;
98
131
console . log ( this [ 1 ] . toString ( ) ) ;
99
132
console . log ( this [ 2 ] . toString ( ) ) ;
133
+ console . log ( this [ 3 ] . toString ( ) ) ;
100
134
101
135
console . log ( 'Fastest is ' + this . filter ( 'fastest' ) . pluck ( 'name' ) ) ;
102
136
} )
0 commit comments