-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro.hh
84 lines (66 loc) · 1.59 KB
/
micro.hh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?hh
function f1(): void {
$t0 = microtime(true);
$x = 10;
for ($i = 0; $i < 100000; ++$i) {
$x = ( 2 * $x ) + $x + 1;
}
$t1 = microtime(true);
printf( "t1 result %d time %f seconds no t2 bigSecs\n" , $x, $t1 - $t0 );
}
function f1a(): void {
$t0 = microtime(true);
$x = 10;
$i = 0;
do {
$x = ( 2 * $x ) + $x + 1;
++$i;
} while ($i < 100000);
$t1 = microtime(true);
printf( "t1a result %d time %f sec no t2\n" , $x, $t1 - $t0 );
}
function f2(): void {
$t0 = microtime(true);
$nStrings = 1000;
$nCats = 100000;
// $a1 = Vector{}; // this is always sloer?
$a1 = array();
$c = ord( "a" );
$a1[] = (string) chr($c) ;
for ($x = 1; $x < $nStrings; $x++) {
$a1[] = $a1[ $x - 1] . chr($c) ;
}
$t1 = microtime(true);
$a2 = array();
for ($x = 0; $x < $nCats; $x++) {
$a2[ $x ] = $a1[ $x % count($a1) ] .
$a1[ ( $x + 7 ) % count($a1) ] .
$a1[ ( $x + 17 ) % count($a1) ] .
$a1[ ( $x + 27 ) % count($a1) ] .
$a1[ ( $x + 37 ) % count($a1) ] .
$a1[ ( $x + 47 ) % count($a1) ] .
$a1[ ( $x + 57 ) % count($a1) ] ;
}
$t2 = microtime(true);
printf( "f2 string create (a1 len %d) (a2 len %d) %f sec cat with dot %f\n" ,
count($a1), count($a2), $t1 - $t0, $t2 - $t1 );
}
function f5(): void {
$start = microtime(true);
for ($i = 0; $i < 1000000; ++$i) {
$a = array();
for ($a1 = 0; $a1 < 50; ++$a1 ) {
$a[$a1] = strval($a1);
}
}
printf( "t5 %f seconds\n",microtime(true) - $start) ;
}
function main(): void {
print "quick performance test\n";
f1();
f1a();
f2();
f5();
print "end quick performance test\n";
}
main();