1+ var app = angular . module ( 'jsBenchmark' , [ ] ) ;
2+
3+ app . controller ( 'DataController' , [ '$compile' , function ( $compile ) {
4+ var COPY_BASIC = {
5+ i : 123 ,
6+ str : "foo" ,
7+ date : new Date ( ) ,
8+ sub : { event : "foo" }
9+ } ;
10+ var COPY_ARRAY_BASIC = [ 123 , "foo" , new Date ( ) , { event : "foo" } ] ;
11+ var COPY_ARRAY_SIMPLE = [ 123 , "foo" , new Date ( ) , / f o o / ] ;
12+
13+ var BIG_ARRAY_OBJECTS = new Array ( 50 ) . join ( " " ) . split ( " " ) . map ( function ( s , i ) {
14+ return {
15+ i : i ,
16+ s : s + i ,
17+ o : { foo : "bar" , date : new Date ( ) } ,
18+ a : [ / f o o / , new Int32Array ( ) ]
19+ } ;
20+ } ) ;
21+
22+ var BIG_COMPLICATED_ARRAY_OBJECTS = new Array ( 50 ) . join ( " " ) . split ( " " ) . reduce ( function ( a , s , i ) {
23+ var o = { } ;
24+
25+ o . i = i ;
26+ o . s = s + i ;
27+ o . d = ( i % 5 === 1 ) ? a [ i - 1 ] . d : new Date ( ) ;
28+ o . re = ( i % 5 === 2 ) ? a [ i - 2 ] . re : / f o o b a r / i;
29+ o . a = ( i % 5 === 3 ) ? a [ i - 3 ] . a : [ 'foo' , 123 ] ;
30+
31+ if ( i % 5 === 0 ) {
32+ o . o = o ;
33+ }
34+ if ( i % 4 === 1 ) {
35+ o . p = a [ i - 1 ] ;
36+ }
37+
38+ a . push ( o ) ;
39+ if ( i % 20 === 0 ) {
40+ a . push ( o ) ;
41+ }
42+
43+ return a ;
44+ } , [ ] ) ;
45+
46+ function copy ( what ) {
47+ for ( var i = 0 ; i < 1000 ; i ++ ) {
48+ angular . copy ( what ) ;
49+ }
50+ }
51+
52+ benchmarkSteps . push ( {
53+ name : 'large array of objects' ,
54+ fn : copy . bind ( null , BIG_ARRAY_OBJECTS )
55+ } ) ;
56+ benchmarkSteps . push ( {
57+ name : 'large array of over complicated objects' ,
58+ fn : copy . bind ( null , BIG_COMPLICATED_ARRAY_OBJECTS )
59+ } ) ;
60+ benchmarkSteps . push ( {
61+ name : 'basic + date + 1 recurse' ,
62+ fn : copy . bind ( null , COPY_BASIC )
63+ } ) ;
64+ benchmarkSteps . push ( {
65+ name : 'basic array + date + 1 recurse' ,
66+ fn : copy . bind ( null , COPY_ARRAY_BASIC )
67+ } ) ;
68+ benchmarkSteps . push ( {
69+ name : 'simple' ,
70+ fn : copy . bind ( null , COPY_ARRAY_SIMPLE )
71+ } ) ;
72+ } ] ) ;
73+
74+
75+
76+ angular . bootstrap ( document . querySelector ( "[ng-app-foo]" ) , [ "jsBenchmark" ] ) ;
0 commit comments