Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit ddaee99

Browse files
committed
Add perf test for isolate snapshot and script caching [skip ci]
1 parent a2562ae commit ddaee99

File tree

3 files changed

+500
-1
lines changed

3 files changed

+500
-1
lines changed

‎perf/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ For more details see [phpbench documentation](http://phpbench.readthedocs.io/en/
77
e.g.
88

99
- `./vendor/bin/phpbench run src/SetObjectProperty.php --report=aggregate --retry-threshold=5`
10-
1110
- `./vendor/bin/phpbench run src/CreatePrimitiveValue.php --report=aggregate --retry-threshold=5`
11+
- `./vendor/bin/phpbench run src/IsolateSnapshotAndScriptCaching.php --report=aggregate --retry-threshold=5`
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of the pinepain/php-v8 PHP extension.
5+
*
6+
* Copyright (c) 2015-2018 Bogdan Padalko <pinepain@gmail.com>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\V8\Tests\Perf;
17+
18+
19+
use V8\Context;
20+
use V8\Isolate;
21+
use V8\ScriptCompiler;
22+
use V8\StartupData;
23+
use V8\StringValue;
24+
25+
26+
/**
27+
* @Warmup(10)
28+
* @Revs(100)
29+
* @Iterations(25)
30+
* @BeforeMethods("init")
31+
*/
32+
class IsolateSnapshotAndScriptCaching
33+
{
34+
/**
35+
* @var Isolate
36+
*/
37+
private $isolate;
38+
/**
39+
* @var Context
40+
*/
41+
private $context;
42+
/**
43+
* @var StartupData
44+
*/
45+
private $startup_data;
46+
/**
47+
* @var ScriptCompiler\CachedData
48+
*/
49+
private $cached_data;
50+
51+
private $source = 'function test_snapshot() { return "hello, world";}';
52+
53+
public function init()
54+
{
55+
$this->source = file_get_contents(__DIR__ . '/base.js');
56+
$this->startup_data = StartupData::createFromSource($this->source);
57+
//file_put_contents(__DIR__ . '/base.js.cache', $this->startup_data->getData());
58+
59+
$this->isolate = $isolate = new Isolate();
60+
$this->context = $context = new Context($isolate);
61+
62+
$source_string = new StringValue($isolate, $this->source);
63+
$source = new ScriptCompiler\Source($source_string);
64+
65+
$unbound_script = ScriptCompiler::compileUnboundScript($context, $source);
66+
67+
$this->cached_data = ScriptCompiler::createCodeCache($unbound_script, $source_string);
68+
}
69+
70+
public function benchColdIsolateNoScriptCache()
71+
{
72+
$isolate = new Isolate();
73+
$context = new Context($isolate);
74+
75+
$source_string = new StringValue($isolate, $this->source);
76+
$source = new ScriptCompiler\Source($source_string);
77+
ScriptCompiler::compile($context, $source)->run($context);
78+
}
79+
80+
public function benchColdIsolateWithScriptCache()
81+
{
82+
$isolate = new Isolate();
83+
$context = new Context($isolate);
84+
85+
$source_string = new StringValue($isolate, $this->source);
86+
$source = new ScriptCompiler\Source($source_string, null, $this->cached_data);
87+
ScriptCompiler::compile($context, $source, ScriptCompiler::OPTION_CONSUME_CODE_CACHE)->run($context);
88+
}
89+
90+
public function benchWarmIsolateNoScriptCache()
91+
{
92+
$isolate = new Isolate($this->startup_data);
93+
$context = new Context($isolate);
94+
95+
$source_string = new StringValue($isolate, $this->source);
96+
$source = new ScriptCompiler\Source($source_string);
97+
ScriptCompiler::compile($context, $source)->run($context);
98+
}
99+
100+
public function benchWarmIsolateWithScriptCache()
101+
{
102+
$isolate = new Isolate($this->startup_data);
103+
$context = new Context($isolate);
104+
105+
$source_string = new StringValue($isolate, $this->source);
106+
$source = new ScriptCompiler\Source($source_string, null, $this->cached_data);
107+
ScriptCompiler::compile($context, $source, ScriptCompiler::OPTION_CONSUME_CODE_CACHE)->run($context);
108+
}
109+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /