require __DIR__ . '/../lib/Phlexy/bootstrap.php'; require __DIR__ . '/phpLexerDefinition.php'; if ($argc !== 3) { showHelp('Invalid argument count.'); } $testType = $argv[1]; $testFilesDirectory = $argv[2]; if ($testType === 'php-src-tests') { $codes = getCodes($testFilesDirectory, 'PhpTestFileFilterIterator', 'CodeFilterIterator'); } elseif ($testType === 'code') { $codes = getCodes($testFilesDirectory, 'PhpFileFilterIterator', 'CodeFilterIterator'); } else { showHelp('Invalid test type.'); } $factory = new \Phlexy\LexerFactory\Stateful\UsingCompiledRegex(new \Phlexy\LexerDataGenerator()); $lexer = $factory->createLexer(getPHPLexerDefinition(), 'i'); $myTime = 0; $phpTime = 0; foreach ($codes as $code) { try { $startTime = microtime(true); $myLex = $lexer->lex($code); $myTime += microtime(true) - $startTime; } catch (Exception $e) { echo "\n", 'Exception: ', $codes->getPathName(), "\n"; echo 'Message: ', $e->getMessage(), "\n"; echo 'State stack: ', '[' . implode(', ', $lexer->getStateStack()) . ']'; die; } $startTime = microtime(true); $phpLex = token_get_all($code);
* * Timing PHP lexing of larger TestAbstract file: * Took 0.268701076507570 seconds (Phlexy\Lexer\Stateful\Simple) * Took 0.065788984298706 seconds (Phlexy\Lexer\Stateful\UsingCompiledRegex) */ use Phlexy\Lexer; error_reporting(E_ALL | E_STRICT); require dirname(__FILE__) . '/../lib/Phlexy/bootstrap.php'; /* * Lexer definitions */ $cvsLexerDefinition = array('[^",\\r\\n]+' => 0, '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' => 1, ',' => 2, '\\r?\\n' => 3); $alphabet = range('a', 'z'); $alphabetLexerDefinition = array_combine($alphabet, $alphabet); require __DIR__ . '/phpLexerDefinition.php'; $phpLexerDefinition = getPHPLexerDefinition(); /* * Test data */ $cvsString = trim(str_repeat('hallo world,foo bar,more foo,more bar,"rare , escape",some more,stuff' . "\n", 5000)); $allAString = str_repeat('a', 100000); $allZString = str_repeat('z', 20000); $randomString = ''; for ($i = 0; $i < 50000; ++$i) { $randomString .= $alphabet[mt_rand(0, count($alphabet) - 1)]; } $phpCodeOfThisFile = file_get_contents(__FILE__); $phpCodeOfTestAbstractFile = file_get_contents(__DIR__ . '/../test/Phlexy/Lexer/TestAbstract.php'); // Stateless echo 'Timing lexing of CVS data:', "\n"; testPerformanceOfStatelessLexers($cvsString, $cvsLexerDefinition);