Skip to content

Commit b08369e

Browse files
committed
add WordPress templating system specific test
1 parent 4f2e457 commit b08369e

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

object-vs-file-exists/exists.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
list($script, $option, $n) = $argv;
3+
$s = microtime(true);
4+
5+
function dispatch() {
6+
return file_exists(__FILE__) || file_exists(__FILE__);
7+
}
8+
9+
$range = range(1, $n ?? 1);
10+
foreach ($range as $i) {
11+
dispatch();
12+
}
13+
14+
echo ( microtime(true) - $s) * 1000;

object-vs-file-exists/object.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
list($script, $option, $n) = $argv;
3+
$s = microtime(true);
4+
5+
class testObject {
6+
public function get()
7+
{
8+
foreach (['nil', 'null'] as $v) {
9+
in_array($v, ['null', 'more', 'nil']);
10+
}
11+
}
12+
}
13+
14+
$obj = new testObject;
15+
16+
$range = range(1, $n ?? 1);
17+
foreach ($range as $i) {
18+
$obj->get();
19+
$obj->get();
20+
$obj->get();
21+
}
22+
23+
echo ( microtime(true) - $s) * 1000;

object-vs-file-exists/readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
A not-so-scientific speed test. In WordPress templates are checked using `file_exists` so I want to compare tha methods speed against a collection of `in_array` tests. The reason for this is because I can skip those `file_exists` checks if I override the WordPress template locating system with an array collection.
2+
3+
Run Commands:
4+
5+
```
6+
// args: string "starting with a", "num times to run"
7+
php exists.php a 10000
8+
php object.php a 10000
9+
```
10+
11+
### Small Set ~100 calls
12+
13+
- *Object*: `0.425ms`
14+
- *File*: `0.602ms`
15+
16+
My conclusion is that the replacement can be done without a large performance impact (if not being faster).

0 commit comments

Comments
 (0)