Skip to content

Commit af0ac8b

Browse files
committed
🚀 RELEASE: v1.0.0
1 parent f0dd4e0 commit af0ac8b

7 files changed

Lines changed: 88 additions & 87 deletions

File tree

README.md

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# BenchPress
22

3-
**BenchPress** is a WordPress plugin for benchmarking PHP code snippets, WordPress queries, and other critical operations. It's designed to help developers evaluate and optimize code performance by running benchmarks and capturing snapshots for comparison.
3+
**BenchPress** is a WordPress® plugin for benchmarking PHP code snippets, WordPress® queries, and other critical operations.
4+
5+
It's designed to help developers evaluate and optimize code performance by running benchmarks and capturing snapshots for later comparison.
46
* * *
57

68
## Table of Contents
@@ -19,17 +21,17 @@
1921
## Installation
2022

2123
1. **Download** the plugin ZIP from the [GitHub repository](https://github.com/robertdevore/benchpress).
22-
2. **Upload** it via WordPress Admin:
24+
2. **Upload** it via WordPress® Admin:
2325
- Go to `Plugins` > `Add New`.
2426
- Click `Upload Plugin`, select the downloaded ZIP, and click `Install Now`.
25-
3. **Activate** the plugin via the `Plugins` page in the WordPress Admin.
27+
3. **Activate** the plugin via the `Plugins` page in the WordPress® Admin.
2628
* * *
2729

2830
## Setup
2931

3032
BenchPress automatically creates a custom database table to store snapshots of benchmark results on activation. The plugin also includes settings to customize benchmark runs. To configure these:
3133

32-
1. Go to `BenchPress > Settings` in your WordPress admin sidebar.
34+
1. Go to `BenchPress > Settings` in your WordPress® admin sidebar.
3335
2. Adjust loop counts, post IDs, and other options to customize how each benchmark runs.
3436

3537
* * *
@@ -40,7 +42,7 @@ Once installed and configured, you can run benchmarks, view results, and save sn
4042

4143
1. **Running Benchmarks**:
4244

43-
- Navigate to `BenchPress` in your WordPress admin menu.
45+
- Navigate to `BenchPress` in your WordPress® admin menu.
4446
- Click `Refresh Tests` to run all enabled benchmarks and view results.
4547
2. **Saving Snapshots**:
4648

@@ -67,42 +69,43 @@ BenchPress comes with several built-in benchmarks. Here's a quick overview:
6769
### Adding Custom Benchmarks
6870

6971
BenchPress includes a `benchpress_run_all_benchmarks` filter to allow you to add custom benchmarks. Here's an example of how to add your own benchmark:
70-
```
71-
add_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {
72-
// Define your custom benchmark
73-
$benchmarks[] = custom_benchmark_example();
74-
return $benchmarks;
75-
});
76-
77-
// Custom benchmark function
78-
function custom_benchmark_example() {
79-
$loop_count = get_option( 'custom_benchmark_loop_count', 100000 );
80-
$start_time = microtime( true );
81-
82-
for ( $i = 0; $i < $loop_count; $i++ ) {
83-
$result = $i * 2; // Example operation
84-
}
85-
86-
$execution_time = microtime( true ) - $start_time;
87-
88-
return [
89-
'name' => esc_html__( 'Custom Benchmark', 'benchpress' ),
90-
'execution_time'=> round( $execution_time, 5 ),
91-
'description' => sprintf( esc_html__( 'Executed a loop of %d iterations.', 'benchpress' ), $loop_count ),
92-
];
72+
73+
```
74+
add_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {
75+
// Define your custom benchmark
76+
$benchmarks[] = custom_benchmark_example();
77+
return $benchmarks;
78+
});
79+
80+
// Custom benchmark function
81+
function custom_benchmark_example() {
82+
$loop_count = get_option( 'custom_benchmark_loop_count', 100000 );
83+
$start_time = microtime( true );
84+
85+
for ( $i = 0; $i < $loop_count; $i++ ) {
86+
$result = $i * 2; // Example operation
9387
}
94-
```
88+
89+
$execution_time = microtime( true ) - $start_time;
90+
91+
return [
92+
'name' => esc_html__( 'Custom Benchmark', 'benchpress' ),
93+
'execution_time'=> round( $execution_time, 5 ),
94+
'description' => sprintf( esc_html__( 'Executed a loop of %d iterations.', 'benchpress' ), $loop_count ),
95+
];
96+
}
97+
```
9598

9699
### Removing Benchmarks
97100

98101
If you want to remove a specific benchmark, you can use the same `benchpress_run_all_benchmarks` filter. For example, to remove the "Switch vs Match" benchmark:
99-
```
100-
add_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {
101-
return array_filter( $benchmarks, function( $benchmark ) {
102-
return $benchmark['name'] !== esc_html__( 'Switch vs Match', 'benchpress' );
103-
});
102+
```
103+
add_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {
104+
return array_filter( $benchmarks, function( $benchmark ) {
105+
return $benchmark['name'] !== esc_html__( 'Switch vs Match', 'benchpress' );
104106
});
105-
```
107+
});
108+
```
106109

107110
### Accessing Benchmark Data
108111

assets/css/admin-style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
/* BenchPress icon - Hover color */
1111
#adminmenu .toplevel_page_benchpress:hover .wp-menu-image img {
1212
color: #FFF;
13-
}
13+
}

assets/css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* BenchPress styles */
22

3-
/* Hide empty tablenav div to improve layout */
43
.tablenav.top {
54
display: none;
65
}

benchpress.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @link https://robertdevore.com
77
* @since 1.0.0
8-
* @package Back_In_Stock_Notifications
8+
* @package BenchPress
99
*
1010
* @wordpress-plugin
1111
*
@@ -39,9 +39,9 @@
3939
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
4040

4141
$myUpdateChecker = PucFactory::buildUpdateChecker(
42-
'https://github.com/robertdevore/benchpress/',
43-
__FILE__,
44-
'benchpress'
42+
'https://github.com/robertdevore/benchpress/',
43+
__FILE__,
44+
'benchpress'
4545
);
4646

4747
// Set the branch that contains the stable release.
@@ -127,13 +127,13 @@ function benchpress_render_snapshots_page() {
127127
echo ' <button id="benchpress-clear-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-trash"></span> ' . esc_html__( 'Clear Snapshots', 'benchpress' ) . '</button>';
128128
echo ' <button id="benchpress-download-snapshots-btn" class="button" style="margin-left: 10px;"><span class="dashicons dashicons-download"></span> ' . esc_html__( 'Download Snapshots', 'benchpress' ) . '</button>';
129129
echo '</h1><hr />';
130-
echo '<p><a href="https://robertdevore.com/benchpress-documentation/" target="_blank">' . esc_html__( 'Documentation', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/contact/" target="_blank">' . esc_html__( 'Support', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/wordpress-and-woocommerce-plugins/" target="_blank">' . esc_html__( 'More Plugins', 'benchpress' ) . '</a></p>';
130+
echo '<p><a href="https://robertdevore.com/articles/benchpress/" target="_blank">' . esc_html__( 'Documentation', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/contact/" target="_blank">' . esc_html__( 'Support', 'benchpress' ) . '</a> &middot; <a href="https://robertdevore.com/wordpress-and-woocommerce-plugins/" target="_blank">' . esc_html__( 'More Plugins', 'benchpress' ) . '</a></p>';
131131

132132
$table = new BenchPress_Snapshots_Table();
133133
$table->prepare_items();
134134
$table->display();
135135

136-
// Modal HTML for viewing snapshot data.
136+
// Modal HTML for viewing the snapshot data.
137137
echo '
138138
<div id="snapshotModal" class="snapshot-modal" style="display:none;">
139139
<div class="snapshot-modal-content">
@@ -177,7 +177,7 @@ function benchpress_render_page() {
177177
/**
178178
* Render the BenchPress settings page.
179179
*
180-
* @since 1.0.0
180+
* @since 1.0.0
181181
* @return void
182182
*/
183183
function benchpress_render_settings_page() {
@@ -221,7 +221,7 @@ function benchpress_render_settings_page() {
221221
<a id="benchpress-support-btn" href="https://robertdevore.com/contact/" target="_blank" class="button button-alt" style="margin-left: 10px;">
222222
<span class="dashicons dashicons-format-chat" style="vertical-align: middle;"></span> ' . esc_html__( 'Support', 'benchpress' ) . '
223223
</a>
224-
<a id="benchpress-docs-btn" href="https://robertdevore.com/benchpress-documentation/" target="_blank" class="button button-alt" style="margin-left: 5px;">
224+
<a id="benchpress-docs-btn" href="https://robertdevore.com/articles/benchpress/" target="_blank" class="button button-alt" style="margin-left: 5px;">
225225
<span class="dashicons dashicons-media-document" style="vertical-align: middle;"></span> ' . esc_html__( 'Documentation', 'benchpress' ) . '
226226
</a>
227227
</h1><hr />';

classes/BenchPress_Snapshots_Table.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// Snapshot List Table class
2+
// Snapshot List Table class.
33
if ( ! class_exists( 'WP_List_Table' ) ) {
44
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
55
}
@@ -8,8 +8,8 @@ class BenchPress_Snapshots_Table extends WP_List_Table {
88

99
public function __construct() {
1010
parent::__construct([
11-
'singular' => __( 'Snapshot', 'benchpress' ),
12-
'plural' => __( 'Snapshots', 'benchpress' ),
11+
'singular' => esc_html__( 'Snapshot', 'benchpress' ),
12+
'plural' => esc_html__( 'Snapshots', 'benchpress' ),
1313
'ajax' => false,
1414
]);
1515
}
@@ -19,9 +19,9 @@ public function __construct() {
1919
*/
2020
public function get_columns() {
2121
return [
22-
'id' => __( 'ID', 'benchpress' ),
23-
'created_at' => __( 'Date', 'benchpress' ),
24-
'snapshot_data'=> __( 'Actions', 'benchpress' ),
22+
'id' => esc_html__( 'ID', 'benchpress' ),
23+
'created_at' => esc_html__( 'Date', 'benchpress' ),
24+
'snapshot_data'=> esc_html__( 'Actions', 'benchpress' ),
2525
];
2626
}
2727

@@ -79,19 +79,19 @@ protected function column_default( $item, $column_name ) {
7979
return esc_html( date_i18n( get_option( 'date_format' ), strtotime( $item['created_at'] ) ) );
8080
case 'snapshot_data':
8181
$encoded_data = esc_attr( json_encode( json_decode( $item['snapshot_data'], true ) ) );
82-
83-
// View (eye) and Delete (trash) buttons
82+
83+
// View (eye) and Delete (trash) buttons.
8484
return sprintf(
8585
'<button class="button view-data-btn" data-snapshot="%s" aria-label="%s"><span class="dashicons dashicons-visibility"></span></button>
8686
<button class="button delete-snapshot-btn" data-id="%d" aria-label="%s" style="margin-left: 5px;"><span class="dashicons dashicons-trash"></span></button>',
8787
$encoded_data,
88-
__( 'View Data', 'benchpress' ),
88+
esc_html__( 'View Data', 'benchpress' ),
8989
esc_attr( $item['id'] ),
90-
__( 'Delete Snapshot', 'benchpress' )
90+
esc_html__( 'Delete Snapshot', 'benchpress' )
9191
);
9292
default:
9393
return print_r( $item, true );
9494
}
95-
}
96-
95+
}
96+
9797
}

classes/BenchPress_Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function get_columns() {
3838
* Prepare items for the table.
3939
*/
4040
public function prepare_items() {
41-
$benchmarks = benchpress_run_all_benchmarks();
41+
$benchmarks = benchpress_run_all_benchmarks();
4242
$this->items = $benchmarks;
4343

44-
$columns = $this->get_columns();
44+
$columns = $this->get_columns();
4545
$this->_column_headers = [ $columns, [], [] ];
4646
}
4747

0 commit comments

Comments
 (0)