Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added benchmark suite #2153

Merged
merged 27 commits into from Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1ffe936
Added benchmark suite
RunDevelopment Jan 4, 2020
4641f8c
Allow relative file paths
RunDevelopment Jan 4, 2020
e55dae5
Added relative mean (not documented)
RunDevelopment Jan 10, 2020
fe1259e
Minor changes
RunDevelopment Jan 15, 2020
7b575e3
Merge branch 'master' into benchmark
RunDevelopment Jan 15, 2020
a4d029e
Merge branch 'master' into benchmark
RunDevelopment Mar 20, 2020
e8a2a0e
Automatically download files from URL in config
RunDevelopment Mar 20, 2020
b8fef48
Remove `prism.js file
RunDevelopment Mar 20, 2020
817d1b4
Added new option to test remotes only
RunDevelopment Mar 20, 2020
ce91f90
Merge branch 'master' into benchmark
RunDevelopment May 1, 2020
3744401
Added real website and C files
RunDevelopment May 1, 2020
c5b94bf
Added Ruby and Rust
RunDevelopment May 1, 2020
fb50825
Removed last local file
RunDevelopment May 1, 2020
4a05e7c
Added minified jquery
RunDevelopment May 19, 2020
15ab4ee
Merge branch 'master' into benchmark
RunDevelopment Sep 18, 2020
2ca5dda
Updated paths
RunDevelopment Sep 18, 2020
d365dbd
Merge branch 'master' into benchmark
RunDevelopment Sep 22, 2020
7ecf87f
Merge branch 'master' into benchmark
RunDevelopment Dec 28, 2020
dc02e91
Removed files dir
RunDevelopment Dec 28, 2020
ee21d65
Minor refactoring
RunDevelopment Aug 7, 2021
b7b3ad9
Merge branch 'master' into benchmark
RunDevelopment Aug 7, 2021
e8eeacf
Fixed file path
RunDevelopment Aug 7, 2021
a030a1b
Added ESlint and fixed type errors
RunDevelopment Aug 7, 2021
a0067a9
Fixed linting error
RunDevelopment Aug 7, 2021
2de5572
Fixed web page
RunDevelopment Aug 7, 2021
870246b
Use `Array.from` API better
RunDevelopment Aug 13, 2021
9db6918
Added a little comment explaining moe
RunDevelopment Aug 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc.js
Expand Up @@ -188,10 +188,11 @@ module.exports = {
}
},
{
// Gulp and Danger
// Gulp, Danger, and benchmark
files: [
'gulpfile.js/**',
'dangerfile.js'
'dangerfile.js',
'benchmark/**',
],
env: {
es6: true,
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,6 @@ node_modules
.idea/
.DS_Store
.eslintcache

benchmark/remotes/
benchmark/downloads/
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -5,6 +5,7 @@ hide-*.js
.DS_Store
CNAME
.github/
benchmark/
assets/
docs/
examples/
Expand Down
144 changes: 144 additions & 0 deletions benchmark.html
@@ -0,0 +1,144 @@
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8" />
<link rel="icon" href="assets/favicon.png" />
<title>Benchmark ▲ Prism</title>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<script src="assets/vendor/prefixfree.min.js"></script>

<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>
</head>
<body class="language-javascript">

<header>
<div class="intro" data-src="assets/templates/header-main.html" data-type="text/html"></div>

<h2>Benchmark</h2>
<p>Prism has a benchmark suite which can be run and extended similar to the test suite.</p>
</header>

<section id="running-a-benchmark">
<h1>Running a benchmark</h1>

<pre><code class="language-bash">npm run benchmark</code></pre>

<p>By default, the benchmark will be run for the current local version of your repository (the one which is currently checkout) and the <a href="https://github.com/PrismJS/prism/tree/master">PrismJS master branch</a>.</p>

<p>All <code>options</code> in <code>benchmark/config.json</code> can be changed by either directly editing the file or by passing arguments to the run command. I.e. you can overwrite the default <code>maxTime</code> value with 10s by running the following command:</p>

<pre><code class="language-bash">npm run benchmark -- --maxTime=10</code></pre>

<section id="running-a-benchmark-for-specific-languages">
<h2>Running a benchmark for specific languages</h2>

<p>To run the tests only for a certain set of languages, you can use the <code>language</code> option:</p>
<pre><code class="language-bash">npm run benchmark -- --language=javascript,markup</code></pre>
</section>
</section>

<section id="remotes">
<h1>Remotes</h1>

<p>Remotes all you to compare different branches from different repos or the same repo. Repos can be the PrismJS repo or any your fork.</p>

<p>All remotes are specified under the <code>remotes</code> section in <code>benchmark/config.json</code>. To add a new remote, add an object with the <code>repo</code> and <code>branch</code> properties to the array. Note: if the branch property is not specified, the <code>master</code> branch will be used. <br>
Example:</p>

<pre><code class="language-javascript">{
repo: 'https://github.com/MyUserName/prism.git',
branch: 'feature-1'
}</code></pre>

<p>To remove a remote, simply remove (delete or comment out) its entry in the <code>remotes</code> array.</p>
</section>

<section id="cases">
<h1>Cases</h1>

<p>A case is a collection of files where each file will be benchmarked with all candidates (local + remotes) and a specific language.</p>

<p>The language of a case is determined by its key in the <code>cases</code> object in <code>benchmark/config.json</code> where the key has to have the same format as the directory names in <code class="language-text">tests/languages/</code>. Example:</p>
<pre><code class="language-javascript">cases: {
'css!+css-extras': ...
}</code></pre>

<p>The files of a case can be specified by:</p>

<ul>
<li>
<p>Specifying the URI of files. A URI is either an HTTPS URL or a file path relative to <code>./benchmark/</code>.</p>
<pre><code class="language-javascript">cases: {
'css': {
files: [
'style.css',
'https://foo.com/main.css'
]
}
}</code></pre>
</li>
<li>
<p>Using <code>extends</code> to copy all files from another case.</p>
<pre><code class="language-javascript">cases: {
'css': { files: [ 'style.css' ] },
'css!+css-extras': {
extends: 'css'
}
}</code></pre>
</li>
</ul>
</section>

<section id="output-explained">
<h1>Output explained</h1>

<p>The output of a benchmark might look like this:</p>

<pre><code class="language-none">Found 1 cases with 2 files in total.
Test 3 candidates on tokenize
Estimated duration: 1m 0s</code></pre>

<p>The first few lines give some information on the benchmark which is about to be run. This includes the number of cases (here 1), the total number of files in all cases (here 2), the number of candidates (here 3), the test function (here <code>tokenize</code>), and a time estimate for how long the benchmark will take (here 1 minute).</p>

<p>What follows are the results for all cases and their files:</p>

<pre><code class="language-none">json

components.json (25 kB)
| local 5.45ms ± 13% 138smp
| PrismJS@master 4.92ms ± 2% 145smp
| RunDevelopment@greedy-fix 5.62ms ± 4% 128smp
package-lock.json (189 kB)
| local 117.75ms ± 27% 27smp
| PrismJS@master 121.40ms ± 32% 29smp
| RunDevelopment@greedy-fix 190.79ms ± 41% 20smp</code></pre>

<p>A case starts with its key (here <code>json</code>) and is followed by all of its files (here <code>components.json</code> and <code>package-lock.json</code>). Under each file, the results for local and all remotes are shown. To explain the meaning of the values, let's pick a single line:</p>

<code class="language-none">PrismJS@master 121.40ms ± 32% 29smp</code>

<p>First comes the name of the remote (here PrismJS@master) followed by the mean of all samples, the relative margin of error, and the number of samples.</p>

<p>The last part of the output is a small summary of all cases which simply counts how many times a candidate has been the best or worst for a file.</p>

<pre><code class="language-none">summary
best worst
local 1 1
PrismJS@master 0 1
RunDevelopment@greedy-fix 1 0</code></pre>
</section>


<footer data-src="assets/templates/footer.html" data-type="text/html"></footer>

<script src="assets/vendor/utopia.js"></script>
<script src="prism.js"></script>
<script src="components/prism-bash.js"></script>
<script src="components.js"></script>
<script src="assets/code.js"></script>

</body>
</html>