-
-
Notifications
You must be signed in to change notification settings - Fork 48
Add benchmarks #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add benchmarks #294
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e066b43
Add benchmarks
samdark 77167d8
Apply fixes from StyleCI
StyleCIBot 6e97cfa
Apply Rector changes (CI)
samdark 351fd45
Apply fixes from StyleCI
StyleCIBot 46a0759
Remove workflow
samdark a42f62f
Fix
samdark 029f521
Add event dispatched to require-dev
samdark 7fae7fd
Revert
samdark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,7 @@ | ||
| { | ||
| "runner.bootstrap": "vendor/autoload.php", | ||
| "runner.path": "tests/Benchmark", | ||
| "runner.revs": 1000, | ||
| "runner.iterations": 10, | ||
| "runner.retry_threshold": 2 | ||
| } |
This file contains hidden or 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,74 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Files\FileHelper; | ||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\View; | ||
|
|
||
| final class BlocksBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $basePath = __DIR__ . '/../public/tmp/blocks-bench'; | ||
| FileHelper::ensureDirectory($basePath); | ||
|
|
||
| $contentView = $basePath . '/content.php'; | ||
| if (!is_file($contentView)) { | ||
| file_put_contents( | ||
| $contentView, | ||
| <<<'PHP' | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** @var \Yiisoft\View\View $this */ | ||
|
|
||
| $this->setBlock('block-id-1', '...content of block1...'); | ||
| $this->setBlock('block-id-2', '...content of block2...'); | ||
| PHP | ||
| ); | ||
| } | ||
|
|
||
| $layoutView = $basePath . '/layout.php'; | ||
| if (!is_file($layoutView)) { | ||
| file_put_contents( | ||
| $layoutView, | ||
| <<<'PHP' | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** @var \Yiisoft\View\View $this */ | ||
| ?> | ||
| <?php if ($this->hasBlock('block-id-1')): ?> | ||
| <?= $this->getBlock('block-id-1') ?> | ||
| <?php else: ?> | ||
| ... default content for block1 ... | ||
| <?php endif; ?> | ||
|
|
||
| <?php if ($this->hasBlock('block-id-2')): ?> | ||
| <?= $this->getBlock('block-id-2') ?> | ||
| <?php else: ?> | ||
| ... default content for block2 ... | ||
| <?php endif; ?> | ||
| PHP | ||
| ); | ||
| } | ||
|
|
||
| $this->view = new View($basePath, new SimpleEventDispatcher()); | ||
| } | ||
|
|
||
| public function benchRenderBlocksWithTemplates(): void | ||
| { | ||
| // Render content view to define blocks. | ||
| $this->view->render('content'); | ||
|
|
||
| // Render layout view which reads the defined blocks. | ||
| $this->view->render('layout'); | ||
| } | ||
| } |
This file contains hidden or 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,79 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Files\FileHelper; | ||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\TemplateRendererInterface; | ||
| use Yiisoft\View\View; | ||
| use Yiisoft\View\ViewInterface; | ||
|
|
||
| final class MultiRendererBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $basePath = __DIR__ . '/../public/tmp/multi-renderer-bench'; | ||
| FileHelper::ensureDirectory($basePath); | ||
|
|
||
| $phpView = $basePath . '/view.php'; | ||
| if (!is_file($phpView)) { | ||
| file_put_contents( | ||
| $phpView, | ||
| <<<'PHP_WRAP' | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** @var \Yiisoft\View\View $this */ | ||
|
|
||
| echo 'PHP view'; | ||
| PHP_WRAP | ||
| ); | ||
| } | ||
|
|
||
| $bladeView = $basePath . '/view.blade.php'; | ||
| if (!is_file($bladeView)) { | ||
| file_put_contents($bladeView, 'Blade view'); | ||
| } | ||
|
|
||
| $tplView = $basePath . '/view.tpl'; | ||
| if (!is_file($tplView)) { | ||
| file_put_contents($tplView, 'TPL view'); | ||
| } | ||
|
|
||
| $this->view = (new View($basePath, new SimpleEventDispatcher())) | ||
| ->withRenderers([ | ||
| 'blade' => new class () implements TemplateRendererInterface { | ||
| public function render(ViewInterface $view, string $template, array $parameters): string | ||
| { | ||
| return file_get_contents($template); | ||
| } | ||
| }, | ||
| 'tpl' => new class () implements TemplateRendererInterface { | ||
| public function render(ViewInterface $view, string $template, array $parameters): string | ||
| { | ||
| return file_get_contents($template); | ||
| } | ||
| }, | ||
| ]); | ||
| } | ||
|
|
||
| public function benchRenderPhpView(): void | ||
| { | ||
| $this->view->render('view'); | ||
| } | ||
|
|
||
| public function benchRenderBladeView(): void | ||
| { | ||
| $this->view->render('view.blade.php'); | ||
| } | ||
|
|
||
| public function benchRenderTplView(): void | ||
| { | ||
| $this->view->render('view.tpl'); | ||
| } | ||
| } | ||
This file contains hidden or 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,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Files\FileHelper; | ||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\View; | ||
|
|
||
| final class NestedViewsBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $basePath = __DIR__ . '/../public/tmp/nested-bench'; | ||
| FileHelper::ensureDirectory($basePath); | ||
|
|
||
| $baseView = $basePath . '/base.php'; | ||
| $subDir = $basePath . '/sub'; | ||
| FileHelper::ensureDirectory($subDir); | ||
|
|
||
| if (!is_file($baseView)) { | ||
| file_put_contents( | ||
| $baseView, | ||
| <<<'PHP' | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** @var \Yiisoft\View\View $this */ | ||
|
|
||
| echo $this->render('./sub/sub'); | ||
| PHP | ||
| ); | ||
| } | ||
|
|
||
| $subView = $subDir . '/sub.php'; | ||
| if (!is_file($subView)) { | ||
| file_put_contents($subView, 'nested-view-content'); | ||
| } | ||
|
|
||
| $this->view = new View($basePath, new SimpleEventDispatcher()); | ||
| } | ||
|
|
||
| public function benchRenderNestedView(): void | ||
| { | ||
| $this->view->render('base'); | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\View; | ||
|
|
||
| final class ViewBasicBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->view = new View(__DIR__ . '/../public/view', new SimpleEventDispatcher()); | ||
| } | ||
|
|
||
| public function benchRenderSimpleView(): void | ||
| { | ||
| $this->view->render('only-content', [ | ||
| 'content' => 'benchmark', | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or 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,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Files\FileHelper; | ||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\View; | ||
|
|
||
| final class ViewLocaleBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $basePath = __DIR__ . '/../public/tmp/locale-bench'; | ||
|
|
||
| FileHelper::ensureDirectory($basePath . '/es'); | ||
|
|
||
| file_put_contents($basePath . '/file.php', 'test en render'); | ||
| file_put_contents($basePath . '/es/file.php', 'test es render'); | ||
|
|
||
| $this->view = new View($basePath, new SimpleEventDispatcher()); | ||
| $this->view->setLocale('es'); | ||
| } | ||
|
|
||
| public function benchRenderLocalizedView(): void | ||
| { | ||
| $this->view->render('file'); | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\View\Tests\Benchmark; | ||
|
|
||
| use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher; | ||
| use Yiisoft\View\Theme; | ||
| use Yiisoft\View\View; | ||
|
|
||
| final class ViewThemeBench | ||
| { | ||
| private readonly View $view; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $basePath = __DIR__ . '/../public/view'; | ||
| $themePath = __DIR__ . '/../public/tmp/theme-basic/views'; | ||
|
|
||
| @mkdir($themePath, 0777, true); | ||
|
|
||
| // ensure themed file exists | ||
| $sourceFile = $basePath . '/only-content.php'; | ||
| $themedFileDir = dirname($themePath . '/only-content.php'); | ||
| @mkdir($themedFileDir, 0777, true); | ||
| if (is_file($sourceFile) && !is_file($themePath . '/only-content.php')) { | ||
| copy($sourceFile, $themePath . '/only-content.php'); | ||
| } | ||
|
|
||
| $theme = new Theme([ | ||
| $basePath => $themePath, | ||
| ]); | ||
|
|
||
| $this->view = new View($basePath, new SimpleEventDispatcher()); | ||
| $this->view->setTheme($theme); | ||
| } | ||
|
|
||
| public function benchRenderThemedView(): void | ||
| { | ||
| $this->view->render('only-content', [ | ||
| 'content' => 'benchmark', | ||
| ]); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heredoc content has inconsistent leading whitespace. Lines 28-33 have excessive leading spaces that will be included in the file content, which may not be intended.