Skip to content

Commit fd7b45c

Browse files
add benchmark that we run in CI
1 parent 6b9abed commit fd7b45c

File tree

4 files changed

+169
-31
lines changed

4 files changed

+169
-31
lines changed

.github/workflows/build-test-lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ jobs:
4444
- name: Run lint
4545
run: npm run lint
4646

47+
- name: Run benchmark
48+
run: php tests/benchmarks/plugin.php
49+

tests/benchmarks/plugin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/mocks.php';
4+
5+
// make sure we're not running through all migrations
6+
update_option('koko_analytics_version', '1.6.2');
7+
8+
$memory = memory_get_usage();
9+
$time_start = microtime(true);
10+
11+
require dirname(__DIR__, 2) . '/koko-analytics.php';
12+
13+
$time = round((microtime(true) - $time_start) * 1000, 2);
14+
$memory_used = (memory_get_usage() - $memory) >> 10;
15+
16+
echo "Memory: $memory_used KB\n";
17+
echo "Time: $time ms\n";

tests/bootstrap.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,6 @@
22

33
// phpcs:disable PSR1.Files.SideEffects
44

5-
require dirname(__DIR__) . '/koko-analytics.php';
5+
require __DIR__ . '/mocks.php';
66

7-
function apply_filters($a, $b, $prio = 10, $args = 2)
8-
{
9-
return $b;
10-
}
11-
function add_action($a, $b, $c = 10, $d = 1)
12-
{
13-
}
14-
function add_filter($a, $b, $c = 10, $d = 1)
15-
{
16-
}
17-
function add_shortcode($a, $b)
18-
{
19-
}
20-
function number_format_i18n($number, $decimals = 0)
21-
{
22-
return number_format($number, $decimals);
23-
}
24-
function register_activation_hook($file, $callback)
25-
{
26-
}
27-
function register_deactivation_hook($file, $callback)
28-
{
29-
}
30-
function update_option($a, $b, $c = false)
31-
{
32-
}
33-
function get_option($a, $b = null)
34-
{
35-
return $b;
36-
}
7+
require dirname(__DIR__) . '/koko-analytics.php';

tests/mocks.php

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
/*
4+
* phpcs:disable PSR1.Files.SideEffects
5+
* phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
6+
*/
7+
8+
define('ABSPATH', dirname(__DIR__, 1));
9+
define('HOUR_IN_SECONDS', 3600);
10+
11+
$options = [];
12+
13+
function is_admin()
14+
{
15+
return false;
16+
}
17+
18+
function apply_filters($a, $b, $prio = 10, $args = 2)
19+
{
20+
return $b;
21+
}
22+
23+
function add_action($hook, $callback, $c = 10, $d = 1)
24+
{
25+
if ($hook === 'init') {
26+
$callback();
27+
}
28+
}
29+
30+
function add_filter($hook, $callback, $c = 10, $d = 1)
31+
{
32+
}
33+
34+
function add_shortcode($a, $b)
35+
{
36+
}
37+
38+
function number_format_i18n($number, $decimals = 0)
39+
{
40+
return number_format($number, $decimals);
41+
}
42+
43+
function register_activation_hook($file, $callback)
44+
{
45+
}
46+
47+
function register_deactivation_hook($file, $callback)
48+
{
49+
}
50+
51+
function update_option($option_name, $value, $autoload = false)
52+
{
53+
global $options;
54+
$options[$option_name] = $value;
55+
}
56+
57+
function get_option($option_name, $default = null)
58+
{
59+
global $options;
60+
return $options[$option_name] ?? $default;
61+
}
62+
63+
function get_transient($name)
64+
{
65+
return null;
66+
}
67+
68+
function set_transient($name, $value, $ttl)
69+
{
70+
}
71+
72+
function delete_transient($name)
73+
{
74+
}
75+
76+
function get_role($role)
77+
{
78+
return null;
79+
}
80+
81+
function get_site_url()
82+
{
83+
return '';
84+
}
85+
86+
function site_url()
87+
{
88+
return '';
89+
}
90+
91+
function is_multisite()
92+
{
93+
return false;
94+
}
95+
96+
function wp_next_scheduled($event)
97+
{
98+
return false;
99+
}
100+
101+
function wp_schedule_event($timestamp, $recurrence, $hook, $args = [])
102+
{
103+
}
104+
105+
function wp_upload_dir()
106+
{
107+
return [
108+
'basedir' => '/tmp',
109+
];
110+
}
111+
112+
function wp_remote_get($url)
113+
{
114+
return null;
115+
}
116+
117+
function wp_remote_retrieve_response_code($response)
118+
{
119+
return '';
120+
}
121+
122+
function wp_remote_retrieve_headers($response)
123+
{
124+
return [];
125+
}
126+
127+
function is_wp_error($thing)
128+
{
129+
return false;
130+
}
131+
132+
class wpdb_mock
133+
{
134+
public $prefix = '';
135+
public function query($sql)
136+
{
137+
return null;
138+
}
139+
140+
public function prepare($query, ...$params)
141+
{
142+
return $query;
143+
}
144+
}
145+
146+
global $wpdb;
147+
$wpdb = new wpdb_mock();

0 commit comments

Comments
 (0)