{"id":21049431,"url":"https://github.com/robertdevore/benchpress","last_synced_at":"2025-04-12T16:50:58.269Z","repository":{"id":262197917,"uuid":"885674770","full_name":"robertdevore/benchpress","owner":"robertdevore","description":"BenchPress is a WordPress plugin for benchmarking PHP code snippets, WordPress queries, and other critical operations. ","archived":false,"fork":false,"pushed_at":"2025-02-06T08:38:56.000Z","size":273,"stargazers_count":50,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T11:11:21.476Z","etag":null,"topics":["performance","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"https://robertdevore.com/introducing-benchpress/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertdevore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T04:57:28.000Z","updated_at":"2025-02-06T08:37:45.000Z","dependencies_parsed_at":"2024-12-22T07:25:11.872Z","dependency_job_id":"1669d00b-a55d-4473-af37-1c95998dd8df","html_url":"https://github.com/robertdevore/benchpress","commit_stats":null,"previous_names":["robertdevore/benchpress"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdevore%2Fbenchpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdevore%2Fbenchpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdevore%2Fbenchpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdevore%2Fbenchpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertdevore","download_url":"https://codeload.github.com/robertdevore/benchpress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248601221,"owners_count":21131607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["performance","wordpress","wordpress-plugin"],"created_at":"2024-11-19T15:12:10.711Z","updated_at":"2025-04-12T16:50:58.235Z","avatar_url":"https://github.com/robertdevore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BenchPress\n\n**BenchPress** is a WordPress® plugin for benchmarking PHP code snippets, WordPress® queries, and other critical operations. \n\nIt's designed to help developers evaluate and optimize code performance by running benchmarks and capturing snapshots for later comparison.\n* * *\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Setup](#setup)\n- [Usage](#usage)\n- [Available Benchmarks](#available-benchmarks)\n- [Customizing Benchmarks](#customizing-benchmarks)\n- [Snapshots](#snapshots)\n- [Plugin Settings](#plugin-settings)\n- [Contributing](#contributing)\n- [License](#license)\n* * *\n\n## Installation\n\n1. **Download** the plugin ZIP from the [GitHub repository](https://github.com/robertdevore/benchpress).\n2. **Upload** it via WordPress® Admin:\n    - Go to `Plugins` \u003e `Add New`.\n    - Click `Upload Plugin`, select the downloaded ZIP, and click `Install Now`.\n3. **Activate** the plugin via the `Plugins` page in the WordPress® Admin.\n* * *\n\n## Setup\n\nBenchPress 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:\n\n1. Go to `BenchPress \u003e Settings` in your WordPress® admin sidebar.\n2. Adjust loop counts, post IDs, and other options to customize how each benchmark runs.\n\n* * *\n\n## Usage\n\nOnce installed and configured, you can run benchmarks, view results, and save snapshots for later reference:\n\n1. **Running Benchmarks**:\n\n    - Navigate to `BenchPress` in your WordPress® admin menu.\n    - Click `Refresh Tests` to run all enabled benchmarks and view results.\n2. **Saving Snapshots**:\n\n    - On the main `BenchPress` page, click `Save Snapshot` to save a record of the current benchmark results.\n3. **Viewing Snapshots**:\n\n    - Go to `BenchPress \u003e Snapshots` to view all saved snapshots. Each snapshot can be viewed, downloaded, or deleted.\n* * *\n\n## Available Benchmarks\n\nBenchPress comes with several built-in benchmarks. Here's a quick overview:\n\n- **Switch vs. Match**: Compares the performance of PHP `switch` vs `match` statements.\n- **Transient vs. Direct Query**: Tests the speed of transient caching against direct database queries.\n- **Post Meta Access**: Compares `get_post_meta()` with `WP_Meta_Query` for retrieving post meta data.\n- **WP_Query by ID**: Measures query performance for retrieving single or multiple posts.\n- **Array Merge vs. Union**: Compares `array_merge` with the array union (`+`) operator.\n- **String Concatenation**: Benchmarks PHP's `.` operator vs `sprintf`.\n* * *\n\n## Customizing Benchmarks\n\n### Adding Custom Benchmarks\n\nBenchPress 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:\n\n```\nadd_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {\n    // Define your custom benchmark\n    $benchmarks[] = custom_benchmark_example();\n    return $benchmarks;\n});\n\n// Custom benchmark function\nfunction custom_benchmark_example() {\n    $loop_count = get_option( 'custom_benchmark_loop_count', 100000 );\n    $start_time = microtime( true );\n\n    for ( $i = 0; $i \u003c $loop_count; $i++ ) {\n        $result = $i * 2; // Example operation\n    }\n\n    $execution_time = microtime( true ) - $start_time;\n\n    return [\n        'name'          =\u003e esc_html__( 'Custom Benchmark', 'benchpress' ),\n        'execution_time'=\u003e round( $execution_time, 5 ),\n        'description'   =\u003e sprintf( esc_html__( 'Executed a loop of %d iterations.', 'benchpress' ), $loop_count ),\n    ];\n}\n```\n\n### Removing Benchmarks\n\nIf 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:\n```\nadd_filter( 'benchpress_run_all_benchmarks', function( $benchmarks ) {\n    return array_filter( $benchmarks, function( $benchmark ) {\n        return $benchmark['name'] !== esc_html__( 'Switch vs Match', 'benchpress' );\n    });\n});\n```\n\n### Accessing Benchmark Data\n\nTo access saved snapshots for analysis or custom display, use the custom database table created by BenchPress, which stores each snapshot as JSON data.\n\n* * *\n\n## Snapshots\n\nSnapshots are records of benchmark results that you can refer back to later. Snapshots can be managed in the `BenchPress \u003e Snapshots` page:\n\n- **Clear Snapshots**: Clears all stored snapshots.\n- **Download Snapshots**: Downloads all snapshots as a CSV file.\n* * *\n\n## Plugin Settings\n\nTo configure BenchPress benchmarks, navigate to `BenchPress \u003e Settings`. Options include:\n\n- **Loop Count for Benchmarks**: Set the number of iterations for each benchmark.\n- **Enable Benchmarks**: Select which benchmarks to run.\n- **WP_Query Settings**: Configure `WP_Query` options, including post types, IDs, taxonomy terms, etc.\n* * *\n\n## Contributing\n\nBenchPress is an open-source project, and contributions are welcome! \n\nTo contribute:\n\n1. **Fork** the repository.\n2. **Create** a new branch for your feature or fix.\n3. **Submit** a pull request with a clear description of your changes.\n* * *","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdevore%2Fbenchpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertdevore%2Fbenchpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdevore%2Fbenchpress/lists"}