Skip to content

Commit

Permalink
Remove benchmarking code from the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
limzykenneth committed Jan 18, 2020
1 parent 1957f26 commit eae2119
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 1,302 deletions.
6 changes: 2 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -5,11 +5,11 @@
In the description field of this PR, include "resolves #XXXX" tagging the issue you are fixing. If this PR addresses the issue but doesn't completely resolve it (ie the issue should remain open after your PR is merged), write "addresses #XXXX".-->
Resolves #[Add issue number here]

Changes:
Changes:
<!-- Add here what changes were made in this pull request and if possible provide links showcasing the changes. -->


Screenshots of the change:
Screenshots of the change:
<!-- If applicable, add screenshots depicting the changes. -->

#### PR Checklist
Expand All @@ -20,8 +20,6 @@ Resolves #[Add issue number here]
- [ ] `npm run lint` passes
- [ ] [Inline documentation] is included / updated
- [ ] [Unit tests] are included / updated
- [ ] [Benchmarks] are included / updated

[Inline documentation]: https://github.com/processing/p5.js/blob/master/contributor_docs/inline_documentation.md
[Unit tests]: https://github.com/processing/p5.js/tree/master/contributor_docs#unit-tests
[Benchmarks]: https://github.com/processing/p5.js/blob/master/contributor_docs/benchmarking_p5.md
22 changes: 1 addition & 21 deletions Gruntfile.js
Expand Up @@ -42,17 +42,6 @@
* docs, and does not perform linting, minification,
* or run tests. It's faster than watch:main.
*
* grunt karma - This runs the performance benchmarks in
* multiple real browsers on the developers local machine.
* It will automatically detect which browsers are
* installed from the following list (Chrome, Firefox,
* Safari, Edge, IE) and run the benchmarks in all installed
* browsers and report the results. Running "grunt karma"
* will execute ALL the benchmarks. If you want to run a
* specific benchmark you can by specifying the target e.g.
* "grunt karma:random-dev". The available targets are
* defined in grunt-karma.js.
*
* Contributors list can be updated using all-contributors-cli:
* https://www.npmjs.com/package/all-contributors-cli
*
Expand Down Expand Up @@ -98,9 +87,6 @@ module.exports = grunt => {
const quietReport = process.env.GITHUB_ACTIONS || grunt.option('quiet');
const reporter = quietReport ? 'spec' : 'Nyan';

// Load karma tasks from an external file to keep this file clean
const karmaTasks = require('./grunt-karma.js');

// For the static server used in running tests, configure the keepalive.
// (might not be useful at all.)
let keepalive = false;
Expand Down Expand Up @@ -147,7 +133,6 @@ module.exports = grunt => {
build: {
src: [
'Gruntfile.js',
'grunt-karma.js',
'docs/preprocessor.js',
'utils/**/*.js',
'tasks/**/*.js'
Expand All @@ -172,7 +157,7 @@ module.exports = grunt => {
src: ['src/**/*.js']
},
test: {
src: ['bench/**/*.js', 'test/**/*.js', '!test/js/*.js']
src: ['test/**/*.js', '!test/js/*.js']
}
},

Expand Down Expand Up @@ -312,10 +297,6 @@ module.exports = grunt => {
}
},

// This runs benchmarks in multiple real browsers for developing
// performance optimizations
karma: karmaTasks,

// This is a static server which is used when testing connectivity for the
// p5 library. This avoids needing an internet connection to run the tests.
// It serves all the files in the test directory at http://localhost:9001/
Expand Down Expand Up @@ -453,7 +434,6 @@ module.exports = grunt => {
grunt.loadNpmTasks('grunt-minjson');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-simple-nyc');

Expand Down
30 changes: 0 additions & 30 deletions bench/math/random-fe-off.bench.js

This file was deleted.

30 changes: 0 additions & 30 deletions bench/math/random-fe-on.bench.js

This file was deleted.

17 changes: 0 additions & 17 deletions bench/math/sin.bench.js

This file was deleted.

1 change: 0 additions & 1 deletion contributor_docs/README.md
Expand Up @@ -26,7 +26,6 @@ Aside from the code itself, you may also need to supply some combination of the

- [inline documentation](./inline_documentation.md) in the form of code comments, which explain the code both to other developers and to users. Many of these comments must conform to [JSDoc](https://jsdoc.app) syntax and will be published on the p5.js website as part of the [online reference manual](https://p5js.org/reference/)
- [unit tests](./unit_testing.md), small pieces of code which are separate from the library and are used to verify its behavior
- [benchmarks](./benchmarking_p5.md) to test performance

## Examples

Expand Down
118 changes: 1 addition & 117 deletions contributor_docs/benchmarking_p5.md
@@ -1,119 +1,3 @@
# Benchmarking p5.js

We have a grunt task that runs performance benchmarks in multiple real browsers on the developers local machine. It will automatically detect which browsers are installed from the following list (Chrome, Firefox, Safari, Edge, IE) and run the benchmarks in all installed browsers and report the results.

Our benchmarking system consists of 3 main components:

1. [Benchmark.js](https://benchmarkjs.com/) - The engine that runs the benchmarks and the framework for defining benchmarks.
2. [karma-benchmark](https://www.npmjs.com/package/karma-benchmark) - The karma plugin for launching and running the benchmarks in multiple real browsers.
3. [grunt-karma](https://www.npmjs.com/package/grunt-karma) - The grunt plugin that allows us to define different karma configurations per grunt command. This allows us to run single benchmarks or groups of benchmarks.

## Basic instructions:
### Install the new dependancies

npm ci

### Do a build, the benchmarks expect a local build of p5.js and p5.min.js

grunt

### Run a specific benchmark

grunt karma:<target_benchmark>

### To run all the benchmarks

grunt karma

### Example

grunt karma:random-dev

Outputs:
```
Chrome 62.0.3202 (Linux 0.0.0)
p5 random() vs Math.random(): Math.random() at 95811115 ops/sec (1.26x faster than p5 random())
Firefox 56.0.0 (Fedora 0.0.0)
p5 random() vs Math.random(): Math.random() at 2367566507 ops/sec (1.14x faster than p5 random())
Done, without errors.
```

## Adding new benchmarks
1. Create a new benchmark file at this path and name format: bench/*.bench.js
2. Write the benchmark here is documentation [karma-benchmark](https://github.com/JamieMason/karma-benchmark/blob/master/README.md)
3. Add the benchmark target to `grunt-karma.js`

### Example benchmark [random-fe-off.bench.js]

Here is an example benchmark that compares p5 random() to Math.random() with Friendly Error System disabled. It has two suites one for instanced mode and one using the global window random().

```JavaScript
p5.disableFriendlyErrors = true;

const p5Inst = new p5();

/**
* Instance random() vs Math.random()
*/
suite('Friendly Errors: OFF, Instance random() vs Math.random()', function () {
benchmark('Instance random()', () => p5Inst.random());

benchmark('Math.random()', () => Math.random());
});


/**
* Window random() vs Math.random()
*/
suite('Friendly Errors: OFF, Window random() vs Math.random()', function () {
benchmark('window random()', () => random());

benchmark('Math.random()', () => Math.random());
});
```
Then you would need to add your new benchmark to `grunt-karma.js`

```JavaScript
...
'random-fe-off-dev': {
options: {
files: [
'lib/p5.js',
'bench/math/random-fe-off.bench.js'
]
}
}
...
```
Now you can run your new benchmark with:

grunt karma:random-fe-off-dev

## Comparing Prod to Dev
karma-benchmark can load remote files. So it's easy to include the p5.js prod build and compare it to the dev build. This is important when you're working on improving performance to compare your changes to what is in production. To do this simply make two targets in `grunt-karma.js` one for prod and one for dev.

```
'random-prod': {
options: {
files: [
'https://cdnjs.cloudflare.com/ajax/libs/p5.js/<%= pkg.version %>/p5.js',
'bench/random.bench.js',
],
},
},
'random-dev': {
options: {
files: [
'lib/p5.js',
'bench/random.bench.js',
],
},
},
```
You can see that `random-prod` actually loads the latest build from CDN. Then to compare you can run both targets using:

grunt karma:random-prod karma:random-dev

## Notes
I chose to put the grunt-karma tasks in it's own file `grunt-karma.js` instead of the main `Gruntfile.js`, because as we add more benchmarks overtime the file could grow quite long, and I wanted to keep the main Gruntfile clean.
Benchmarking has been moved to its own repo available at https://github.com/limzykenneth/p5-benchmark. A overall view of the benchmark result of the latest version of p5.js can be seen at https://limzykenneth.github.io/p5-benchmark/. This is still a work in progress.
1 change: 0 additions & 1 deletion contributor_docs/pt-br/README.md
Expand Up @@ -26,7 +26,6 @@ Além do código em si, também pode ser necessário fornecer alguma combinaçã

- [documentação embutida](./inline_documentation.md) na forma de comentários de código, que explicam o código para outros desenvolvedores e usuários. Muitos desses comentários devem estar em conformidade com a sintaxe [JSDoc](https://usejsdoc.org) e serão publicados no site p5.js como parte do [manual de referência on-line](https://p5js.org/reference/ )
- [testes de unidade](./unit_testing.md), pequenos pedaços de código que são separados da biblioteca e são usados para verificar seu comportamento
- [benchmarks](./benchmarking_p5.md) para testar o desempenho

## Exemplos

Expand Down
1 change: 0 additions & 1 deletion contributor_docs/sk/README.md
Expand Up @@ -26,7 +26,6 @@ Mimo samotného kódu je potrebné aby si dodal aj kombináciu z nasledovných.

- [inline dokumentácia](./inline_documentation.md) vo forme komentárov kódu, ktoré vysvetľujú kód vývojárom a používateľom. Mnohé z týchto komentárom musia podliehať syntaxi [JSDoc](https://jsdoc.app) a budú publikované na stránke p5.js ako súčasť [online referenčnej príručky](https://p5js.org/reference/)
- [unit testy](./unit_testing.md), malé časti kódu, ktoré sú oddelené od knižnice a použite na overenie správnosti správanie
- [benchmarky](./benchmarking_p5.md) na testovanie výkonu

## Príklady

Expand Down
66 changes: 0 additions & 66 deletions grunt-karma.js

This file was deleted.

0 comments on commit eae2119

Please sign in to comment.