Skip to content
New issue

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

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

Already on GitHub? # to your account

Add support for running benchmarks in a browser #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ The following code will only cause a single DOM manipulation:
</body>
</html>
```

## Benchmarks

The `/bench` directory includes a number of performance benchmarks.

To run in `node`:

```bash
yarn ember build
node ./bench/index.js # (all benchmarks)
node ./bench/index.js ./bench/benches/some-file.js # (specific benchmark)
```

Or to run in a browser, run `yarn ember server`, and visit `http://localhost:4200` in a browser. Be aware that having the developer tools open/closed can affect JS performance.
2 changes: 0 additions & 2 deletions bench/benches/debounce-cancel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var Backburner = require('../../dist/backburner').default;

function sharedSetup() {
var backburner = new this.Backburner(["sync", "actions", "routerTransitions", "render", "afterRender", "destroy", "rsvpAfter"]);

Expand Down
2 changes: 0 additions & 2 deletions bench/benches/later-cancel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var Backburner = require('../../dist/backburner').default;

function sharedSetup() {
var backburner = new this.Backburner(["sync", "actions", "routerTransitions", "render", "afterRender", "destroy", "rsvpAfter"]);

Expand Down
2 changes: 0 additions & 2 deletions bench/benches/schedule-cancel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var Backburner = require('../../dist/backburner').default;

function sharedSetup() {
var backburner = new this.Backburner(["sync", "actions", "routerTransitions", "render", "afterRender", "destroy", "rsvpAfter"]);

Expand Down
2 changes: 0 additions & 2 deletions bench/benches/schedule-flush.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var Backburner = require('../../dist/backburner').default;

function prodSetup() {
var backburner = new this.Backburner(["sync", "actions", "routerTransitions", "render", "afterRender", "destroy", "rsvpAfter"]);

Expand Down
2 changes: 0 additions & 2 deletions bench/benches/throttle-cancel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var Backburner = require('../../dist/backburner').default;

function sharedSetup() {
var backburner = new this.Backburner(["sync", "actions", "routerTransitions", "render", "afterRender", "destroy", "rsvpAfter"]);

Expand Down
29 changes: 29 additions & 0 deletions bench/browser-bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import bench from "do-you-even-bench";
import Benchmark from "benchmark";
window.Benchmark = Benchmark;

import DebounceCancel from "./benches/debounce-cancel";
import LaterCancel from "./benches/later-cancel";
import ScheduleCancel from "./benches/schedule-cancel";
import ScheduleFlush from "./benches/schedule-flush";
import ThrottleCancel from "./benches/throttle-cancel";

let suites = [
DebounceCancel,
LaterCancel,
ScheduleCancel,
ScheduleFlush,
ThrottleCancel,
].flat();

const searchParams = new URLSearchParams(window.location.search);
const filter = searchParams.get("filter");

if (filter) {
document.querySelector("input[name=filter]").value = filter;
suites = suites.filter((s) =>
s.name.toLowerCase().includes(filter.toLowerCase())
);
}

bench(suites);
25 changes: 25 additions & 0 deletions bench/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Backburner.js Benchmarks</title>
</head>
<body>
<form method="get">
<label for="filter">Filter by benchmark name:</label>
<input name="filter" type="text" />
<button type="submit">Go</button>
</form>
<pre id="output">
</pre>
<script src="/ember-cli-live-reload.js" type="text/javascript"></script>
<script src="../loader.js"></script>
<script src="../named-amd/backburner.js"></script>
<script src="lodash.js"></script>
<script src="browser-bench.js"></script>
<script>
window.Backburner = require("backburner").default;
require("browser-bench");
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ if (process.argv[2]) {
console.log(fileGlob);
}

globalThis.Backburner = require("../dist/backburner").default;

var suites = [];
glob.sync(fileGlob).forEach(function(file) {
var exported = require( path.resolve( file ) );
Expand Down
34 changes: 31 additions & 3 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ module.exports = function (app) {
files: ['qunit.css', 'qunit.js']
}),
new Funnel(path.dirname(require.resolve('loader.js')), {
annotation: 'tests/loader.js',
destDir: 'tests',
annotation: 'loader.js',
destDir: '',
files: ['loader.js']
}),
new Funnel(compiled, {
Expand All @@ -108,7 +108,35 @@ module.exports = function (app) {
new Funnel(__dirname + '/tests', {
destDir: 'tests',
files: ['index.html']
})
}),
new Funnel(__dirname + "/bench", {
destDir: "bench",
files: ["index.html"],
}),
new Rollup(__dirname + "/bench", {
rollup: {
treeshake: false,
input: "browser-bench.js",
external: ["backburner"],
plugins: [
resolve(),
commonjs(),
loadWithInlineMap(),
],
output: [
{
file: "bench/browser-bench.js",
format: "amd",
amd: { id: "browser-bench" },
sourcemap: true,
},
],
},
}),
new Funnel(path.dirname(require.resolve("lodash")), {
destDir: "bench",
files: ["lodash.js"],
}),
], {
annotation: 'dist'
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ember-cli-inject-live-reload": "2.0.2",
"glob": "^7.1.6",
"loader.js": "^4.7.0",
"lodash": "^4.17.21",
"lolex": "^6.0.0",
"qunit": "^2.14.1",
"release-it": "^14.2.1",
Expand Down
2 changes: 1 addition & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script src="/ember-cli-live-reload.js" type="text/javascript"></script>
<script src="qunit.js"></script>
<script src="/testem.js"></script>
<script src="loader.js"></script>
<script src="/loader.js"></script>
<script src="../named-amd/backburner.js"></script>
<script src="../named-amd/tests.js"></script>
<script>
Expand Down