File tree Expand file tree Collapse file tree 8 files changed +236
-0
lines changed
2013_05/03_More_Fast_PHP/benchmark Expand file tree Collapse file tree 8 files changed +236
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+
7
+ function benchmark ($ arr )
8
+ {
9
+ $ start = microtime (true );
10
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
11
+ $ arr [$ i ] = $ i ;
12
+ }
13
+
14
+ return microtime (true ) - $ start ;
15
+ }
16
+
17
+ $ a1 = array ();
18
+ print benchmark ($ a1 )."\n" ;;
19
+ unset($ a1 );
20
+
21
+ $ a2 = new SplFixedArray (ARRAY_SIZE );
22
+ print benchmark ($ a2 )."\n" ;;
23
+ unset($ a2 );
24
+
25
+ $ a3 = new Judy (Judy::INT_TO_INT );
26
+ print benchmark ($ a3 )."\n" ;;
27
+ unset($ a3 );
28
+
29
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+
7
+ function benchmark ($ arr )
8
+ {
9
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
10
+ $ arr [$ i ] = $ i ;
11
+ }
12
+
13
+ $ start = microtime (true );
14
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
15
+ $ k = $ arr [$ i ];
16
+ }
17
+
18
+ return microtime (true ) - $ start ;
19
+ }
20
+
21
+ $ a1 = array ();
22
+ print benchmark ($ a1 )."\n" ;;
23
+ unset($ a1 );
24
+
25
+ $ a2 = new SplFixedArray (ARRAY_SIZE );
26
+ print benchmark ($ a2 )."\n" ;;
27
+ unset($ a2 );
28
+
29
+ $ a3 = new Judy (Judy::INT_TO_INT );
30
+ print benchmark ($ a3 )."\n" ;;
31
+ unset($ a3 );
32
+
33
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+
7
+ function benchmark ($ arr )
8
+ {
9
+ $ start = microtime (true );
10
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
11
+ $ arr [rand (0 , ARRAY_SIZE - 1 )] = $ i ;
12
+ }
13
+
14
+ return microtime (true ) - $ start ;
15
+ }
16
+
17
+ $ a1 = array ();
18
+ print benchmark ($ a1 )."\n" ;;
19
+ unset($ a1 );
20
+
21
+ $ a2 = new SplFixedArray (ARRAY_SIZE );
22
+ print benchmark ($ a2 )."\n" ;;
23
+ unset($ a2 );
24
+
25
+ $ a3 = new Judy (Judy::INT_TO_INT );
26
+ print benchmark ($ a3 )."\n" ;;
27
+ unset($ a3 );
28
+
29
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+
7
+ function benchmark ($ arr )
8
+ {
9
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
10
+ $ arr [$ i ] = $ i ;
11
+ }
12
+
13
+ $ start = microtime (true );
14
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
15
+ $ k = $ arr [rand (0 , ARRAY_SIZE - 1 )];
16
+ }
17
+
18
+ return microtime (true ) - $ start ;
19
+ }
20
+
21
+ $ a1 = array ();
22
+ print benchmark ($ a1 )."\n" ;;
23
+ unset($ a1 );
24
+
25
+ $ a2 = new SplFixedArray (ARRAY_SIZE );
26
+ print benchmark ($ a2 )."\n" ;;
27
+ unset($ a2 );
28
+
29
+ $ a3 = new Judy (Judy::INT_TO_INT );
30
+ print benchmark ($ a3 )."\n" ;;
31
+ unset($ a3 );
32
+
33
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+ const GAP = 100000 ;
7
+
8
+ function benchmark ($ arr )
9
+ {
10
+ $ start = microtime (true );
11
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
12
+ $ arr [$ i * GAP ] = $ i ;
13
+ }
14
+
15
+ return microtime (true ) - $ start ;
16
+ }
17
+
18
+ $ a1 = array ();
19
+ print benchmark ($ a1 )."\n" ;;
20
+ unset($ a1 );
21
+
22
+ $ a3 = new Judy (Judy::INT_TO_INT );
23
+ print benchmark ($ a3 )."\n" ;;
24
+ unset($ a3 );
25
+
26
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+ const GAP = 100000 ;
7
+
8
+ function benchmark ($ arr )
9
+ {
10
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
11
+ $ arr [$ i * GAP ] = $ i ;
12
+ }
13
+
14
+ $ start = microtime (true );
15
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
16
+ $ k = $ arr [$ i * GAP ];
17
+ }
18
+
19
+ return microtime (true ) - $ start ;
20
+ }
21
+
22
+ $ a1 = array ();
23
+ print benchmark ($ a1 )."\n" ;;
24
+ unset($ a1 );
25
+
26
+ $ a3 = new Judy (Judy::INT_TO_INT );
27
+ print benchmark ($ a3 )."\n" ;;
28
+ unset($ a3 );
29
+
30
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+ const GAP = 100000 ;
7
+
8
+ function benchmark ($ arr )
9
+ {
10
+ $ start = microtime (true );
11
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
12
+ $ arr [rand (0 , ARRAY_SIZE - 1 ) * GAP ] = $ i ;
13
+ }
14
+
15
+ return microtime (true ) - $ start ;
16
+ }
17
+
18
+ $ a1 = array ();
19
+ print benchmark ($ a1 )."\n" ;;
20
+ unset($ a1 );
21
+
22
+ $ a3 = new Judy (Judy::INT_TO_INT );
23
+ print benchmark ($ a3 )."\n" ;;
24
+ unset($ a3 );
25
+
26
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ ini_set ('memory_limit ' , '1G ' );
4
+
5
+ const ARRAY_SIZE = 5000000 ;
6
+ const GAP = 100000 ;
7
+
8
+ function benchmark ($ arr )
9
+ {
10
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
11
+ $ arr [$ i * GAP ] = $ i ;
12
+ }
13
+
14
+ $ start = microtime (true );
15
+ for ($ i = 0 ; $ i < ARRAY_SIZE ; $ i ++) {
16
+ $ k = $ arr [rand (0 , ARRAY_SIZE - 1 ) * GAP ];
17
+ }
18
+
19
+ return microtime (true ) - $ start ;
20
+ }
21
+
22
+ $ a1 = array ();
23
+ print benchmark ($ a1 )."\n" ;;
24
+ unset($ a1 );
25
+
26
+ $ a3 = new Judy (Judy::INT_TO_INT );
27
+ print benchmark ($ a3 )."\n" ;;
28
+ unset($ a3 );
29
+
30
+ ?>
You can’t perform that action at this time.
0 commit comments