Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f7bf118

Browse files
committed
test(benchmarks): adding basic benchmark to measure random js snippets
1 parent a69251a commit f7bf118

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

benchmarks/js-bp/app.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var app = angular.module('jsBenchmark', []);
2+
3+
app.controller('DataController', ['$compile', function($compile) {
4+
var COPY_BASIC = {
5+
i: 123,
6+
str: "foo",
7+
date: new Date(),
8+
sub: {event: "foo"}
9+
};
10+
var COPY_ARRAY_BASIC = [123, "foo", new Date(), {event: "foo"}];
11+
var COPY_ARRAY_SIMPLE = [123, "foo", new Date(), /foo/];
12+
13+
var BIG_ARRAY_OBJECTS = new Array(50).join(" ").split(" ").map(function(s, i) {
14+
return {
15+
i: i,
16+
s: s + i,
17+
o: {foo: "bar", date: new Date()},
18+
a: [/foo/, new Int32Array()]
19+
};
20+
});
21+
22+
var BIG_COMPLICATED_ARRAY_OBJECTS = new Array(50).join(" ").split(" ").reduce(function(a, s, i) {
23+
var o = {};
24+
25+
o.i = i;
26+
o.s = s + i;
27+
o.d = (i % 5 === 1) ? a[i-1].d : new Date();
28+
o.re = (i % 5 === 2) ? a[i-2].re : /foobar/i;
29+
o.a = (i % 5 === 3) ? a[i-3].a : ['foo', 123];
30+
31+
if (i % 5 === 0) {
32+
o.o = o;
33+
}
34+
if (i % 4 === 1) {
35+
o.p = a[i-1];
36+
}
37+
38+
a.push(o);
39+
if (i % 20 === 0) {
40+
a.push(o);
41+
}
42+
43+
return a;
44+
}, []);
45+
46+
function copy(what) {
47+
for (var i=0; i<1000; i++) {
48+
angular.copy(what);
49+
}
50+
}
51+
52+
benchmarkSteps.push({
53+
name: 'large array of objects',
54+
fn: copy.bind(null, BIG_ARRAY_OBJECTS)
55+
});
56+
benchmarkSteps.push({
57+
name: 'large array of over complicated objects',
58+
fn: copy.bind(null, BIG_COMPLICATED_ARRAY_OBJECTS)
59+
});
60+
benchmarkSteps.push({
61+
name: 'basic + date + 1 recurse',
62+
fn: copy.bind(null, COPY_BASIC)
63+
});
64+
benchmarkSteps.push({
65+
name: 'basic array + date + 1 recurse',
66+
fn: copy.bind(null, COPY_ARRAY_BASIC)
67+
});
68+
benchmarkSteps.push({
69+
name: 'simple',
70+
fn: copy.bind(null, COPY_ARRAY_SIMPLE)
71+
});
72+
}]);
73+
74+
75+
76+
angular.bootstrap(document.querySelector("[ng-app-foo]"), ["jsBenchmark"]);

benchmarks/js-bp/bp.conf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function(config) {
2+
config.set({
3+
scripts: [{
4+
id: 'jquery',
5+
src: 'jquery-noop.js'
6+
},
7+
{
8+
id: 'angular',
9+
src: '/build/angular.js'
10+
},
11+
{
12+
src: 'app.js',
13+
}]
14+
});
15+
};

benchmarks/js-bp/jquery-noop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//Override me with ?jquery=/bower_components/jquery/dist/jquery.js

benchmarks/js-bp/main.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div ng-app-foo>
2+
<div ng-controller="DataController as ctrl"></div>
3+
</div>

0 commit comments

Comments
 (0)