Skip to content

Instantly share code, notes, and snippets.

@pqr
Created September 3, 2014 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pqr/59f8b6b16c234380abb8 to your computer and use it in GitHub Desktop.
Save pqr/59f8b6b16c234380abb8 to your computer and use it in GitHub Desktop.
<?php
/* скрипт для запуска тестов для стати http://pqr7.wordpress.com/2014/09/03/haskell-vs-php/ */
function runTest($cmd, $content) {
$time = microtime(true);
$descriptorspec = [];
$descriptorspec[0] = ['pipe', 'r']; //stdin
$descriptorspec[1] = ['pipe', 'w']; //stdout
$process = proc_open($cmd, $descriptorspec, $pipes, null, null, ['bypass_shell' => true]);
//Пишем в stdin 50 раз, чтобы было побольше контента!
for($i = 0; $i < 50; $i++) {
if ($i) {
fwrite($pipes[0], "\r\n");
}
fwrite($pipes[0], $content);
}
fclose($pipes[0]);
$outtext = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
print $cmd . ":\n";
print "Result blocks found: " . $outtext;
print "\n";
print "Time: " . (microtime(true) - $time);
print "\n\n";
}
$content = file_get_contents(__DIR__ . "/example.txt");
runTest("HaskellReal.exe", $content);
runTest("php php_imperative.php", $content);
runTest("php php_functional.php", $content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment