Skip to content

Commit 732fad4

Browse files
committed
Initial commit
0 parents  commit 732fad4

File tree

8 files changed

+146
-0
lines changed

8 files changed

+146
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[{README.md,package.json,.travis.yml}]
11+
indent_style = space
12+
indent_size = 2

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Automatically normalize line endings for all text-based files
2+
* text=auto

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Built files
2+
dist
3+
4+
# Installed npm modules
5+
node_modules
6+
7+
# Folder view configuration files
8+
.DS_Store
9+
Desktop.ini
10+
11+
# Thumbnail cache files
12+
._*
13+
Thumbs.db
14+
15+
# Files that might appear on external disks
16+
.Spotlight-V100
17+
.Trashes

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
git:
3+
depth: 1
4+
branches:
5+
only:
6+
- /^.*$/

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Benchmark.js wrapper for jsPerf [![Build status](https://travis-ci.org/jsperf/build-benchmark.js-wrapper.svg)](https://travis-ci.org/jsperf/build-benchmark.js-wrapper)
2+
3+
This repository hosts scripts that generate the special jsPerf-specific build of Benchmark.js.
4+
5+
## Why does jsPerf need a special build?
6+
7+
On jsPerf, we want to avoid creating global variables for Benchmark.js’s dependencies such as `_` and `platform`, since they might interfere with people’s tests otherwise.
8+
9+
Additionally, there are some jsPerf-specific settings that are not hardcoded in the distributed versions of Benchmark.js and its jsPerf UI plugin.

gulpfile.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
const gulp = require('gulp');
4+
5+
const addSrc = require('gulp-add-src');
6+
const concat = require('gulp-concat');
7+
const insert = require('gulp-insert');
8+
const remoteSrc = require('gulp-remote-src');
9+
const replace = require('gulp-replace');
10+
const uglify = require('gulp-uglify');
11+
12+
const BENCHMARKJS_VERSION = '2.1.0';
13+
const requestOptions = {
14+
'gzip': true,
15+
'strictSSL': true
16+
};
17+
18+
gulp.task('js', function() {
19+
20+
// Fetch Platform.js, Benchmark.js, and its jsPerf UI dependencies.
21+
remoteSrc([
22+
'bestiejs/platform.js/1.3.1/platform.js',
23+
`bestiejs/benchmark.js/${ BENCHMARKJS_VERSION }/benchmark.js`,
24+
`bestiejs/benchmark.js/${ BENCHMARKJS_VERSION }/example/jsperf/ui.js`,
25+
`bestiejs/benchmark.js/${ BENCHMARKJS_VERSION }/plugin/ui.browserscope.js`,
26+
], {
27+
'base': 'https://raw.githubusercontent.com/',
28+
'requestOptions': requestOptions
29+
}
30+
)
31+
32+
// Use whatever version of lodash Benchmark.js is using.
33+
.pipe(addSrc.prepend(
34+
'node_modules/benchmark/node_modules/lodash/lodash.js'
35+
))
36+
37+
.pipe(concat('all.js'))
38+
39+
// Set the Google Analytics ID.
40+
.pipe(replace('gaId = \'\'', 'gaId = \'UA-6065217-40\''))
41+
42+
// jsPerf is browser-only. Ensure we’re detected as a browser environment,
43+
// even if this is an AMD test, for example.
44+
.pipe(replace(/freeDefine = (?:[^;]+)/, 'freeDefine = false'))
45+
.pipe(replace(/freeExports = (?:[^;]+)/, 'freeExports = false'))
46+
.pipe(replace(/freeModule = (?:[^;]+)/, 'freeModule = false'))
47+
.pipe(replace(/freeRequire = (?:[^;]+)/, 'freeRequire = false'))
48+
.pipe(replace(/(if\s*\()(typeof define|freeDefine)\b/, '$1false'))
49+
50+
// Set the CSS selector for the Browserscope results.
51+
.pipe(replace('\'selector\': \'\'', '\'selector\': \'#bs-results\''))
52+
53+
// Avoid exposing `_` and `platform` as global variables.
54+
.pipe(insert.wrap(
55+
'(function(){var _,platform;',
56+
'}.call(this))'
57+
))
58+
59+
// Minify the result.
60+
//.pipe(uglify())
61+
62+
.pipe(gulp.dest('./dist/'));
63+
});
64+
65+
gulp.task('assets', function() {
66+
// Update Platform.js, Benchmark.js, and its jsPerf UI dependencies.
67+
remoteSrc([
68+
'index.html',
69+
'main.css'
70+
], {
71+
'base': `https://raw.githubusercontent.com/bestiejs/benchmark.js/${ BENCHMARKJS_VERSION }/example/jsperf/`,
72+
'requestOptions': requestOptions
73+
}
74+
)
75+
.pipe(replace('<script src="../../node_modules/lodash/index.js"></script>', ''))
76+
.pipe(replace('<script src="../../node_modules/platform/platform.js"></script>', ''))
77+
.pipe(replace('<script src="../../benchmark.js"></script>', ''))
78+
.pipe(replace('<script src="ui.js"></script>', ''))
79+
.pipe(replace('<script src="../../plugin/ui.browserscope.js"></script>', ''))
80+
.pipe(gulp.dest('./dist'));
81+
});
82+
83+
gulp.task('default', ['js', 'assets']);

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"benchmark": "2.1.0",
5+
"gulp": "^3.9.0",
6+
"gulp-add-src": "^0.2.0",
7+
"gulp-concat": "^2.6.0",
8+
"gulp-insert": "^0.5.0",
9+
"gulp-remote-src": "^0.4.0",
10+
"gulp-replace": "^0.5.4",
11+
"gulp-uglify": "^1.5.1"
12+
},
13+
"scripts": {
14+
"test": "gulp"
15+
}
16+
}

0 commit comments

Comments
 (0)