Created
September 3, 2014 12:58
-
-
Save pqr/59f8b6b16c234380abb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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