forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_get_values.php
More file actions
39 lines (31 loc) · 1010 Bytes
/
java_get_values.php
File metadata and controls
39 lines (31 loc) · 1010 Bytes
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
#!/usr/bin/php
<?php
include_once ("java/Java.inc");
ini_set("max_execution_time", 0);
$System=new JavaClass("java.lang.System");
$n=10000;
for ($i = 0; $i < $n; $i++) {
$temp_array[$i]="$i";
}
// post temp array to java (as hash)
$hash = new java("java.util.Hashtable", $temp_array);
// post temp array to java (as arrayList)
$hashMap = new java("java.util.HashMap", $temp_array);
$now = java_values($System->currentTimeMillis());
// receive Hashtable and Hashmap in one request
$php_hash=java_get_values($hash);
$php_hashMap=java_get_values($hashMap);
echo "array from java_get_values:\n";
for ($i = 0; $i < $n; $i++) {
$val = "($php_hash[$i],$php_hashMap[$i]) ";
}
$now=java_values($System->currentTimeMillis())-$now;
echo "$now (ms)\n\n";
$now = java_values($System->currentTimeMillis());
echo "the same, but slower (uses $n*4 round trips):\n";
for ($i = 0; $i < $n; $i++) {
$val = "($hash[$i],$hashMap[$i])";
}
$now=java_values($System->currentTimeMillis())-$now;
echo "$now (ms)\n";
?>