Bug 1465336 - add six-speed to jsshell-bench framework. r=ahal

This commit is contained in:
Joel Maher 2018-05-30 09:40:00 -04:00
parent 26526a42fa
commit e09ad9e15c
56 changed files with 878 additions and 0 deletions

View File

@ -30,3 +30,15 @@ bench-ares6:
export JSSHELL=$USE_ARTIFACT_PATH/build/jsshell/js &&
cd /builds/worker/checkouts/gecko &&
./mach jsshell-bench --binary $JSSHELL --perfherder ares6
bench-sixspeed:
description: Six-Speed JavaScript shell benchmark suite
treeherder:
symbol: js-bench(6speed)
run:
command: >
cd $USE_ARTIFACT_PATH/build &&
unzip -q -d jsshell target.jsshell.zip &&
export JSSHELL=$USE_ARTIFACT_PATH/build/jsshell/js &&
cd /builds/worker/checkouts/gecko &&
./mach jsshell-bench --binary $JSSHELL --perfherder six-speed

View File

@ -80,6 +80,7 @@ class Benchmark(object):
'shouldAlert': self.should_alert,
'subtests': [],
'units': self.units,
'value': None
},
],
}
@ -158,8 +159,49 @@ class Ares6(Benchmark):
self.suite['value'] = self.last_summary
class SixSpeed(Benchmark):
name = 'six-speed'
path = os.path.join('third_party', 'webkit', 'PerformanceTests', 'six-speed')
units = 'ms'
@property
def command(self):
cmd = super(SixSpeed, self).command
return cmd + ['test.js']
def reset(self):
super(SixSpeed, self).reset()
# Scores are of the form:
# {<bench_name>: {<score_name>: [<values>]}}
self.scores = defaultdict(lambda: defaultdict(list))
def process_line(self, output):
m = re.search("(.+): (\d+)", output)
if not m:
return
subtest = m.group(1)
score = m.group(2)
if subtest not in self.scores[self.name]:
self.scores[self.name][subtest] = []
self.scores[self.name][subtest].append(int(score))
def collect_results(self):
bench_total = 0
# NOTE: for this benchmark we run the test once, so we have a single value array
for bench, scores in self.scores.items():
for score, values in scores.items():
test_name = "{}-{}".format(self.name, score)
total = sum(values) / len(values)
self.suite['subtests'].append({'name': test_name, 'value': total})
bench_total += int(sum(values))
self.suite['value'] = bench_total
all_benchmarks = {
'ares6': Ares6,
'six-speed': SixSpeed,
}

View File

@ -0,0 +1 @@
0.1

View File

@ -0,0 +1,85 @@
function assertEqual() {}
function test(fn) {
var its = iterations;
var start = Date.now();
for (var i = 0; i < its; i++) {
fn();
}
timing = Date.now() - start;
}
var tests = [
"template_string",
"defaults",
"map-set-lookup",
"spread",
"object-assign",
"spread-literal",
"map-set",
"destructuring-simple",
"super",
"for-of-object",
"rest",
"regex-u",
"arrow",
"bindings-compound",
"classes",
"template_string_tag",
"map-string",
"arrow-declare",
"spread-generator",
"object-literal-ext",
"generator",
"arrow-args",
"for-of-array",
"bindings",
"destructuring",
"map-set-object"
]
var iteration_for_test = [
200000000,
100000000,
200000,
1000000,
600000,
1000000,
10000,
20000000,
3000000,
1000000,
500000,
1000000,
20000000,
20000000,
10000000,
2000000,
30000000,
30000000,
1000000,
1000000,
3000000,
20000000,
5000000,
20000000,
20000000,
5000
]
for (var z = 0; z < tests.length; z++) {
var timing = 0;
var testname = tests[z];
var iterations = iteration_for_test[z];
// ES5
var content = read("tests/"+testname+".es5")
var func = new Function(content);
func();
print(testname+"-es5:", timing);
// ES6
var content = read("tests/"+testname+".es6")
var func = new Function(content);
func();
print(testname+"-es6:", timing);
}

View File

@ -0,0 +1,16 @@
var obj = {
value: 42,
fn: function() {
var args = arguments;
return function() {
return args[0];
};
}
};
var fn = obj.fn(1);
assertEqual(fn(), 1);
test(function() {
fn();
});

View File

@ -0,0 +1,14 @@
var obj = {
value: 42,
fn: function() {
return () => arguments[0];
}
};
var fn = obj.fn(1);
assertEqual(fn(), 1);
test(function() {
fn();
});

View File

@ -0,0 +1,14 @@
var obj = {
value: 42,
fn: function() {
return function() {
return obj.value;
};
}
};
assertEqual(obj.fn()(), 42);
test(function() {
obj.fn();
});

View File

@ -0,0 +1,13 @@
var obj = {
value: 42,
fn: function() {
return () => this.value;
}
};
assertEqual(obj.fn()(), 42);
test(function() {
obj.fn();
});

View File

@ -0,0 +1,15 @@
var obj = {
value: 42,
fn: function() {
return function() {
return obj.value;
};
}
};
var fn = obj.fn();
assertEqual(fn(), 42);
test(function() {
fn();
});

View File

@ -0,0 +1,14 @@
var obj = {
value: 42,
fn: function() {
return () => this.value;
}
};
var fn = obj.fn();
assertEqual(fn(), 42);
test(function() {
fn();
});

View File

@ -0,0 +1,11 @@
var b = 2;
assertEqual(fn(), 3);
function fn() {
var a = 1;
a += b;
return a;
}
test(fn);

View File

@ -0,0 +1,14 @@
"use strict";
const b = 2;
function fn() {
let a = 1;
a += b;
return a;
}
assertEqual(fn(), 3);
test(fn);

View File

@ -0,0 +1,8 @@
var a = 1,
b = 2;
assertEqual(a+b, 3);
test(function() {
return a + b;
});

View File

@ -0,0 +1,10 @@
"use strict";
const a = 1;
let b = 2;
assertEqual(a+b, 3);
test(function() {
return a + b;
});

View File

@ -0,0 +1,11 @@
function C() {
this.foo = 'bar';
}
C.prototype.bar = function() {
};
assertEqual(new C().foo, 'bar');
test(function() {
return new C();
});

View File

@ -0,0 +1,13 @@
class C {
constructor() {
this.foo = 'bar';
}
bar() {
}
}
assertEqual(new C().foo, 'bar');
test(function() {
return new C();
});

View File

@ -0,0 +1,14 @@
function fn(arg, other) {
arg = arg === undefined ? 1 : arg;
other = other === undefined ? 3 : other;
return other;
}
assertEqual(fn(), 3);
assertEqual(fn(1, 2), 2);
test(function() {
fn();
fn(2);
fn(2, 4);
});

View File

@ -0,0 +1,13 @@
function fn(arg = 1, other = 3) {
return other;
}
assertEqual(fn(), 3);
assertEqual(fn(1, 2), 2);
test(function() {
fn();
fn(2);
fn(2, 4);
});

View File

@ -0,0 +1,14 @@
var data = {
a: 'foo',
b: {c: 'd'},
arr: [1, 2, 3]
};
function fn() {
var a = data.a,
b = data.b;
return a;
}
assertEqual(fn(), 'foo');
test(fn);

View File

@ -0,0 +1,14 @@
var data = {
a: 'foo',
b: {c: 'd'},
arr: [1, 2, 3]
};
function fn() {
var {a, b} = data;
return a;
}
assertEqual(fn(), 'foo');
test(fn);

View File

@ -0,0 +1,15 @@
var data = {
a: 'foo',
b: {c: 'd'},
arr: [1, 2, 3]
};
function fn() {
var a = data.a,
b = data.b.c,
c = data.arr[1];
return c;
}
assertEqual(fn(), 2);
test(fn);

View File

@ -0,0 +1,13 @@
var data = {
a: 'foo',
b: {c: 'd'},
arr: [1, 2, 3]
};
function fn() {
var {a, b:{c:b}, arr:[, c]} = data;
return c;
}
assertEqual(fn(), 2);
test(fn);

View File

@ -0,0 +1,13 @@
var data = [1,2,3];
function fn() {
var ret = '';
for (var i = 0; i < data.length; i++) {
ret += data[i];
}
return ret;
}
assertEqual(fn(), '123');
test(fn);

View File

@ -0,0 +1,13 @@
var data = [1,2,3];
function fn() {
var ret = '';
for (var value of data) {
ret += value;
}
return ret;
}
assertEqual(fn(), '123');
test(fn);

View File

@ -0,0 +1,13 @@
var data = {'a': 'b', 'c': 'd'};
function fn() {
var ret = '';
for (var name in data) {
if (data.hasOwnProperty(name)) {
ret += data[name];
}
}
return ret;
}
assertEqual(fn(), 'bd');
test(fn);

View File

@ -0,0 +1,24 @@
var data = {'a': 'b', 'c': 'd'};
data[Symbol.iterator] = function() {
var array = Object.keys(data),
nextIndex = 0;
return {
next: function() {
return nextIndex < array.length ?
{value: data[array[nextIndex++]], done: false} :
{done: true};
}
};
};
function fn() {
var ret = '';
for (var value of data) {
ret += value;
}
return ret;
}
assertEqual(fn(), 'bd');
test(fn);

View File

@ -0,0 +1,26 @@
function generator() {
var i = 0;
return {
next: function() {
i++;
if (i >= 3) {
return {done: true};
} else {
return {
value: i,
done: false
};
}
}
};
}
function fn() {
var iterator = generator();
iterator.next();
iterator.next();
return iterator.next().done;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,14 @@
function * generator() {
yield 1;
yield 2;
}
function fn() {
var iterator = generator();
iterator.next();
iterator.next();
return iterator.next().done;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,21 @@
var keys = [],
values = [],
set = [],
key = {};
for (var i = 0; i < 500; i++) {
keys.push(i);
values.push(i);
set.push(i);
}
keys.push(key);
values.push('bar');
set.push(key);
function fn() {
return set.indexOf(key) >= 0 && keys.indexOf(key) >= 0;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,18 @@
var map = new Map(),
set = new Set(),
key = {};
for (var i = 0; i < 500; i++) {
map.set(i, i);
set.add(i);
}
map.set(key, 'bar');
set.add(key);
function fn() {
return map.has(key) && set.has(key);
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,21 @@
function fn() {
var keys = [],
values = [],
set = [],
key = {};
for (var i = 0; i < 500; i++) {
keys.push(i);
values.push(i);
set.push(i);
}
keys.push(key);
values.push('bar');
set.push(key);
return set.indexOf(key) >= 0 && keys.indexOf(key) >= 0;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,18 @@
function fn() {
var map = new Map(),
set = new Set(),
key = {};
for (var i = 0; i < 500; i++) {
map.set(i, i);
set.add(i);
}
map.set(key, 'bar');
set.add(key);
return map.has(key) && set.has(key);
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,16 @@
function fn() {
var map = {},
set = [];
for (var i = 0; i < 250; i++) {
map[i] = i;
set.push(i);
}
map.foo = 'bar';
set.push('bar');
return ('foo' in map) && set.indexOf('bar') >= 0;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,17 @@
function fn() {
var map = new Map(),
set = new Set();
for (var i = 0; i < 250; i++) {
map.set(i, i);
set.add(i);
}
map.set('foo', 'bar');
set.add('bar');
return map.has('foo') && set.has('bar');
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,12 @@
var map = {};
for (var i = 0; i < 500; i++) {
map[i] = i;
}
function fn() {
return map['499'] === 499;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,12 @@
var map = new Map();
for (var i = 0; i < 500; i++) {
map.set(i + '', i);
}
function fn() {
return map.get('499') === 499;
}
assertEqual(fn(), true);
test(fn);

View File

@ -0,0 +1,28 @@
var obj = {
a: 1,
b: true,
c: function () {},
d: null,
e: 'e'
};
var fn = function (src) {
var o = {};
var keys = Object.keys(src);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
o[key] = src[key];
}
return o;
};
var r = fn(obj);
assertEqual(r.a, obj.a);
assertEqual(r.b, obj.b);
assertEqual(r.c, obj.c);
assertEqual(r.d, obj.d);
assertEqual(r.e, obj.e);
test(function () {
fn(obj);
});

View File

@ -0,0 +1,22 @@
const obj = {
a: 1,
b: true,
c: function () {},
d: null,
e: 'e'
};
const fn = function (src) {
return Object.assign({}, src);
};
const r = fn(obj);
assertEqual(r.a, obj.a);
assertEqual(r.b, obj.b);
assertEqual(r.c, obj.c);
assertEqual(r.d, obj.d);
assertEqual(r.e, obj.e);
test(function () {
fn(obj);
});

View File

@ -0,0 +1,15 @@
function fn() {
var name = 'foo';
var ret = {
'bizz buzz': function() {
return 1;
},
name: name
};
ret[name] = 'bar';
ret[name + 'foo'] = 'foo';
return ret;
}
assertEqual(fn().foofoo, 'foo');
test(fn);

View File

@ -0,0 +1,14 @@
function fn() {
var name = 'foo';
return {
'bizz buzz'() {
return 1;
},
name,
[name]: 'bar',
[name + 'foo']: 'foo'
};
}
assertEqual(fn().foofoo, 'foo');
test(fn);

View File

@ -0,0 +1,6 @@
function fn() {
return '𠮷'.match(/^.$/);
}
// Not asserting as this isn't quite an accurate test under es5
test(fn);

View File

@ -0,0 +1,6 @@
function fn() {
return '𠮷'.match(/^.$/u);
}
assertEqual(!!fn(), true);
test(fn);

View File

@ -0,0 +1,13 @@
function fn() {
return arguments[1];
}
assertEqual(fn(), undefined);
assertEqual(fn(2), undefined);
assertEqual(fn(2, 4), 4);
test(function() {
fn();
fn(2);
fn(2, 4);
});

View File

@ -0,0 +1,13 @@
function fn(foo, ...args) {
return args[0];
}
assertEqual(fn(), undefined);
assertEqual(fn(2), undefined);
assertEqual(fn(2, 4), 4);
test(function() {
fn();
fn(2);
fn(2, 4);
});

View File

@ -0,0 +1,27 @@
function generator() {
var i = 0;
return {
next: function() {
i++;
if (i >= 4) {
return {done: true};
} else {
return {
value: i,
done: false
};
}
}
};
}
function fn() {
var iterator = generator();
var args = [iterator.next().value, iterator.next().value, iterator.next().value];
iterator.next();
return Math.max.apply(Math, args);
}
assertEqual(fn(), 3);
test(fn);

View File

@ -0,0 +1,11 @@
function *generate() {
yield 1;
yield 2;
yield 3;
}
function fn() {
return Math.max(... generate());
}
assertEqual(fn(), 3);
test(fn);

View File

@ -0,0 +1,8 @@
function fn() {
var ret = [1];
ret.push(1, 2, 3);
return ret;
}
assertEqual(fn()[3], 3);
test(fn);

View File

@ -0,0 +1,5 @@
function fn() {
return [1, ... [1, 2, 3]];
}
assertEqual(fn()[3], 3);
test(fn);

View File

@ -0,0 +1,6 @@
function fn() {
return Math.max.apply(Math, [1,2,3]);
}
assertEqual(fn(), 3);
test(fn);

View File

@ -0,0 +1,6 @@
function fn() {
return Math.max(...[1,2,3]);
}
assertEqual(fn(), 3);
test(fn);

View File

@ -0,0 +1,23 @@
function C() {
this.foo = 'bar';
}
C.prototype.bar = function() {
return 41;
};
function D() {
C.call(this);
this.baz = 'bat';
}
D.prototype = Object.create(C.prototype);
D.prototype.bar = function() {
return C.prototype.bar.call(this) + 1;
};
function fn() {
var d = new D();
return d.bar();
}
assertEqual(fn(), 42);
test(fn);

View File

@ -0,0 +1,25 @@
class C {
constructor() {
this.foo = 'bar';
}
bar() {
return 41;
}
}
class D extends C {
constructor() {
super();
this.baz = 'bat';
}
bar() {
return super.bar() + 1;
}
}
function fn() {
var d = new D();
return d.bar();
}
assertEqual(fn(), 42);
test(fn);

View File

@ -0,0 +1,7 @@
var data = [1,2,3];
function fn() {
return data[0] + ' ' + (data[1] + data[2]);
}
assertEqual(fn(), '1 5');
test(fn);

View File

@ -0,0 +1,7 @@
var data = [1,2,3];
function fn() {
return `${data[0]} ${data[1] + data[2]}`;
}
assertEqual(fn(), '1 5');
test(fn);

View File

@ -0,0 +1,11 @@
var data = [1, 2, 3];
function tag(strings, value1, value2) {
return strings[0] + value1 + strings[1] + value2 + strings[2];
}
function fn() {
return tag(['', ' ', ''], data[0], data[1] + data[2]);
}
assertEqual(fn(), '1 5');
test(fn);

View File

@ -0,0 +1,11 @@
var data = [1, 2, 3];
function tag(strings, value1, value2) {
return strings[0] + value1 + strings[1] + value2 + strings[2];
}
function fn() {
return tag`${data[0]} ${data[1] + data[2]}`;
}
assertEqual(fn(), '1 5');
test(fn);