示例#1
0
 public function testCount()
 {
     $cb = Jit::JitFu("ReckiCT\\Mocks\\getCount");
     $array = [];
     for ($i = 0; $i < 1000; $i++) {
         $this->assertEquals($i, $cb($array), "For iteration {$i}");
         $array[] = $i;
     }
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $jit = Jit::getInstance();
     $compiler = new Compiler();
     $ir = '';
     foreach ($input->getArgument('files') as $file) {
         $ir .= "\n" . $jit->getFileIr($file);
     }
     $name = $input->getArgument("name");
     $lname = strtolower($name);
     $files = $compiler->compile(trim($ir), $name);
     $dir = $this->makeTempDir();
     foreach ($files as $fname => $file) {
         file_put_contents($dir . '/' . $fname, $file);
     }
     $opt = $input->getOption("optimize") ? "-O3" : "";
     $command = "(cd {$dir}; phpize && CFLAGS=\"\$CFLAGS {$opt}\" ./configure && make)";
     passthru($command, $retval);
     if ($retval) {
         throw new \RuntimeException("There was an error: {$retval}");
     }
     rename("{$dir}/modules/{$lname}.so", getcwd() . "/{$lname}.so");
     echo "\nGenerated {$lname}.so\n";
 }
示例#3
0
- $1 $8 $9
var $10 long
recurse $9 $10
var $11 numeric
+ $7 $10 $11
return $11
return
end
ENDIR;
/**
 * Compile the function using the JITFU extension!
 *
 * This is extremely cheap, since no analysis needs to happen. All that happens is the IR
 * is turned into JIT-Fu instructions (which are then compiled by libjit).
 */
$func = Jit::getInstance()->compileIrJitFu($ir, 'fibo');
/**
 * Now let's benchmark the two implementations!
 *
 * If you don't have JitFu installed, then both should be equal.
 */
benchmark("fibo", "PHP");
benchmark($func, "ReckiCT");
/**
 * A very light weight benchmark tool, which runs the code 100,000 times.
 *
 * @param callable $func  The function to benchmark
 * @param string   $label The label of the test, for output
 *
 * @return void
 */
示例#4
0
    /**
     * @covers ::getInstance
     * @covers ::__construct
     * @covers ::compileIrJitFu
     */
    public function testCompileIrJitFuWithoutExt()
    {
        $ir = <<<'EOF'
function ReckiCT\test long
param $1 long
begin
return $1
end
EOF;
        $jit = Jit::getInstance();
        $r = new \ReflectionProperty($jit, 'jitfucompiler');
        $r->setAccessible(true);
        $r->setValue($jit, null);
        $func = $jit->compileIrJitFu($ir, __NAMESPACE__ . '\\test');
        $this->assertEquals(__NAMESPACE__ . '\\test', $func);
    }
示例#5
0
 *
 * @param int $n The number of the sequence to generate
 *
 * @return int the fibonacci number!
 */
function fibo($n)
{
    if ($n < 2) {
        return 1;
    }
    return fibo($n - 1) + fibo($n - 2);
}
/**
 * Compile the function using the JITFU extension!
 */
$func = Jit::jitfu('fibo');
/**
 * Now let's benchmark the two implementations!
 *
 * If you don't have JitFu installed, then both should be equal.
 */
benchmark("fibo", "PHP");
benchmark($func, "ReckiCT");
/**
 * A very light weight benchmark tool, which runs the code 100,000 times.
 *
 * For a function that's as CPU intensive as this, Recki-CT should already
 * be orders of magnitude faster than PHP.
 *
 * @param callable $func  The function to benchmark
 * @param string   $label The label of the test, for output
示例#6
0
 * @param int $n The parameter
 *
 * @return int The parameter, returned
 */
function test($n)
{
    return $n;
}
/**
 * Compile the function using the JITFU extension!
 *
 * Note that if the JITFU extension isn't installed, this will simply
 * return a "callable" string (the function name). So you can use it portably
 * across installations.
 */
$func = Jit::jitfu('test');
/**
 * Now let's benchmark the two implementations!
 *
 * If you don't have JitFu installed, then both should be equal.
 */
benchmark("test", "PHP");
benchmark($func, "ReckiCT");
/**
 * A very light weight benchmark tool, which runs the code 100,000 times.
 *
 * For very simple functions like the one we are testing here, we don't expect
 * a lot of gain (if any), since the overhead of the functional call will dominate
 * the runtime.
 *
 * @param callable $func  The function to benchmark