-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmemory_test.php
34 lines (25 loc) · 952 Bytes
/
memory_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use Extism\Manifest;
use Extism\Manifest\PathWasmSource;
use Extism\Plugin;
use Extism\HostFunction;
use Extism\ExtismValType;
use Extism\CurrentPlugin;
require "../vendor/autoload.php";
$wasm = new PathWasmSource(__DIR__ . "/../wasm/count_vowels_kvstore.wasm");
$manifest = new Manifest($wasm);
for ($i = 0; $i < 10_000; $i++) {
$kvstore = [];
$kvRead = new HostFunction("kv_read", [ExtismValType::I64], [ExtismValType::I64], function (CurrentPlugin $p, string $key) use (&$kvstore) {
return $kvstore[$key] ?? "\0\0\0\0";
});
$kvWrite = new HostFunction("kv_write", [ExtismValType::I64, ExtismValType::I64], [], function (string $key, string $value) use (&$kvstore) {
$kvstore[$key] = $value;
});
$plugin = new Plugin($manifest, true, [$kvRead, $kvWrite]);
$output = $plugin->call("count_vowels", "Hello World!");
if ($i % 100 === 0) {
echo "Iteration: $i\n";
}
}
readline();