示例#1
0
#!/usr/bin/php

<?php 
require_once "java/Java.inc";
ini_set("max_execution_time", 0);
$n = 200000;
$Sys = new JavaClass("java.lang.System");
$a1 = array();
for ($i = 0; $i < $n; $i++) {
    $a1[$i] = $i;
}
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
$v = new java("java.util.LinkedList", $a1);
$t2 = java_values($Sys->currentTimeMillis());
$T1 = $t2 - $t1;
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
$v = new java("java.util.HashMap", $a1);
$t2 = java_values($Sys->currentTimeMillis());
$T2 = $t2 - $t1;
$Arrays = new JavaClass("java.util.Arrays");
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
$v = $Arrays->asList($a1);
$t2 = java_values($Sys->currentTimeMillis());
$T3 = $t2 - $t1;
$Sys->gc();
$t1 = java_values($Sys->currentTimeMillis());
java_begin_document();
$v = new java("java.util.LinkedList");
#!/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";