Skip to content

Commit fa3b406

Browse files
committed
배열 벤치마크 소스 코드 추가
1 parent 2bbce69 commit fa3b406

File tree

8 files changed

+236
-0
lines changed

8 files changed

+236
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
?>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
?>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
?>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
?>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
?>

0 commit comments

Comments
 (0)