-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
echo "Running benchmarks...", PHP_EOL; | ||
|
||
$fileList = glob(__DIR__ . "/scripts/*.php"); | ||
$outputList = []; | ||
|
||
foreach($fileList as $phpFile) { | ||
echo "Executing: ", basename($phpFile), PHP_EOL; | ||
|
||
$output = null; | ||
$returnVar = null; | ||
|
||
exec("php " . escapeshellarg($phpFile), $output, $returnVar); | ||
|
||
array_push($outputList, $output); | ||
|
||
if($returnVar !== 0) { | ||
echo "Error: Script ", basename($phpFile), " exited with code $returnVar", PHP_EOL; | ||
} | ||
} | ||
|
||
echo "--------", PHP_EOL; | ||
|
||
foreach($fileList as $i => $file) { | ||
$basename = pathinfo($file, PATHINFO_BASENAME); | ||
echo "$basename output: "; | ||
$output = $outputList[$i]; | ||
|
||
foreach($output as $line) { | ||
echo strlen($line) > 120 ? substr($line, 0, 120) . "..." : $line; | ||
echo PHP_EOL; | ||
} | ||
echo PHP_EOL, "--------", PHP_EOL; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */ | ||
use Dom\HTMLDocument as NativeHTMLDocument; | ||
use Gt\Dom\HTMLDocument; | ||
|
||
require __DIR__ . "/../../../vendor/autoload.php"; | ||
|
||
$timeArray = []; | ||
|
||
foreach([HTMLDocument::class, NativeHTMLDocument::class] as $domClassName) { | ||
$timeStart = microtime(true); | ||
echo "Using $domClassName", PHP_EOL; | ||
$document = match($domClassName) { | ||
HTMLDocument::class => new HTMLDocument(), | ||
NativeHTMLDocument::class => NativeHTMLDocument::createFromString(HTMLDocument::DOCTYPE), | ||
}; | ||
|
||
$element = $document->createElement("example-element"); | ||
$document->body->appendChild($element); | ||
|
||
echo str_replace("\n", "", $document->saveHTML()), PHP_EOL; | ||
$timeEnd = microtime(true); | ||
$timeArray[$domClassName] = $timeEnd - $timeStart; | ||
} | ||
|
||
echo PHP_EOL; | ||
|
||
foreach($timeArray as $className => $time) { | ||
echo "$className: " . number_format($time, 4), PHP_EOL; | ||
} | ||
|
||
$percentDifference = abs( | ||
($timeArray[array_keys($timeArray)[0]] - $timeArray[array_keys($timeArray)[1]]) | ||
/ max($timeArray) * 100 | ||
); | ||
echo "Speed increase: " . number_format($percentDifference, 0) . "%", PHP_EOL; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */ | ||
use Dom\HTMLDocument as NativeHTMLDocument; | ||
use Gt\Dom\HTMLDocument; | ||
|
||
require __DIR__ . "/../../../vendor/autoload.php"; | ||
|
||
$timeArray = []; | ||
|
||
foreach([HTMLDocument::class, NativeHTMLDocument::class] as $domClassName) { | ||
$timeStart = microtime(true); | ||
echo "Using $domClassName", PHP_EOL; | ||
$document = match($domClassName) { | ||
HTMLDocument::class => new HTMLDocument(), | ||
NativeHTMLDocument::class => NativeHTMLDocument::createFromString(HTMLDocument::DOCTYPE), | ||
}; | ||
|
||
for($i = 0; $i < 10_000; $i++) { | ||
$element = $document->createElement("example-element"); | ||
$document->body->appendChild($element); | ||
} | ||
|
||
echo str_replace("\n", "", $document->saveHTML()), PHP_EOL; | ||
$timeEnd = microtime(true); | ||
$timeArray[$domClassName] = $timeEnd - $timeStart; | ||
} | ||
|
||
echo PHP_EOL; | ||
|
||
foreach($timeArray as $className => $time) { | ||
echo "$className: " . number_format($time, 4), PHP_EOL; | ||
} | ||
|
||
$percentDifference = abs( | ||
($timeArray[array_keys($timeArray)[0]] - $timeArray[array_keys($timeArray)[1]]) | ||
/ max($timeArray) * 100 | ||
); | ||
echo "Speed increase: " . number_format($percentDifference, 0) . "%", PHP_EOL; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */ | ||
use Dom\HTMLDocument as NativeHTMLDocument; | ||
use Gt\Dom\HTMLDocument; | ||
|
||
require __DIR__ . "/../../../vendor/autoload.php"; | ||
|
||
$timeArray = []; | ||
|
||
foreach([HTMLDocument::class, NativeHTMLDocument::class] as $domClassName) { | ||
$timeStart = microtime(true); | ||
echo "Using $domClassName", PHP_EOL; | ||
$document = match($domClassName) { | ||
HTMLDocument::class => new HTMLDocument(), | ||
NativeHTMLDocument::class => NativeHTMLDocument::createFromString(HTMLDocument::DOCTYPE), | ||
}; | ||
|
||
for($i = 0; $i < 1_000; $i++) { | ||
$element = $document->createElement("parent-element"); | ||
$document->body->appendChild($element); | ||
|
||
$nested = null; | ||
for($j = 0; $j < 100; $j++) { | ||
$appendTo = $element; | ||
if($nested) { | ||
$appendTo = $nested; | ||
} | ||
$nested = $document->createElement("nested-element$j"); | ||
$appendTo->appendChild($nested); | ||
} | ||
} | ||
|
||
echo str_replace("\n", "", $document->saveHTML()), PHP_EOL; | ||
$timeEnd = microtime(true); | ||
$timeArray[$domClassName] = $timeEnd - $timeStart; | ||
} | ||
|
||
echo PHP_EOL; | ||
|
||
foreach($timeArray as $className => $time) { | ||
echo "$className: " . number_format($time, 4), PHP_EOL; | ||
} | ||
|
||
$percentDifference = abs( | ||
($timeArray[array_keys($timeArray)[0]] - $timeArray[array_keys($timeArray)[1]]) | ||
/ max($timeArray) * 100 | ||
); | ||
echo "Speed increase: " . number_format($percentDifference, 0) . "%", PHP_EOL; |