-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbenchmark.js
147 lines (132 loc) · 3.02 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'use strict';
var Benchmark = require('benchmark');
var Colr = require('./index');
var color = require('color');
var tinycolor = require('tinycolor2');
var chroma = require('chroma-js');
var createSuite = function (name, tests) {
console.log('\n#', name);
var suite = new Benchmark.Suite();
for (var test in tests) {
suite.add(test, tests[test]);
}
suite.on('cycle', function (event) {
console.log(String(event.target));
});
suite.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
});
suite.run();
};
var hex = '#bada55';
var hsv = {h: 180, s:50, v:50};
var hsvArray = [180, 50, 50];
var hsl = {h: 180, s:50, l:50};
var hslArray = [180, 50, 50];
createSuite('FromHsv -> ToRgb', {
colr: function () {
Colr.fromHsvObject(hsv).toRgbObject();
},
color: function () {
color(hsv).rgb();
},
tinycolor: function () {
tinycolor(hsv).toRgb();
},
chroma: function () {
// not exactly fair because chroma doesn't support objects like {h, s,v}
chroma(hsvArray, 'hsv').rgb();
},
});
createSuite('FromHex -> Lighten -> ToHex', {
colr: function () {
Colr.fromHex(hex).lighten(20).toHex();
},
color: function () {
color(hex).lighten(0.2).hexString();
},
tinycolor: function () {
tinycolor(hex).lighten(20).toHexString();
},
chroma: function () {
chroma(hex).brighten(20).hex();
},
});
createSuite('FromHex -> Lighten -> Darken -> ToHex', {
colr: function () {
Colr.fromHex(hex).lighten(10).darken(20).toHex();
},
color: function () {
color(hex).lighten(0.1).darken(0.2).hexString();
},
tinycolor: function () {
tinycolor(hex).lighten(10).darken(20).toHexString();
},
chroma: function () {
chroma(hex).brighten(20).darken(20).hex();
},
});
createSuite('FromHex -> ToHex', {
colr: function () {
Colr.fromHex(hex).toHex();
},
color: function () {
color(hex).hexString();
},
tinycolor: function () {
tinycolor(hex).toHexString();
},
chroma: function () {
chroma(hex).hex();
}
});
createSuite('FromHsv -> ToRgb -> ToHex', {
colr: function () {
var obj = Colr.fromHsvObject(hsv);
obj.toRgbObject();
obj.toHex();
},
color: function () {
var obj = color(hsv);
obj.rgb();
obj.hexString();
},
tinycolor: function () {
var obj = tinycolor(hsv);
obj.toRgb();
obj.toHexString();
},
chroma: function () {
var obj = chroma(hsvArray, 'hsv');
obj.rgb();
obj.hex();
},
});
createSuite('FromHsv -> ToHsl', {
colr: function () {
Colr.fromHsvObject(hsv).toHslObject();
},
color: function () {
color(hsv).hsl();
},
tinycolor: function() {
tinycolor(hsv).toHsv();
},
chroma: function () {
chroma(hsvArray, 'hsv').hsl();
},
});
createSuite('FromHsl -> ToHsv', {
colr: function () {
Colr.fromHslObject(hsl).toHsvObject();
},
color: function () {
color(hsl).hsv();
},
tinycolor: function() {
tinycolor(hsl).toHsl();
},
chroma: function () {
chroma(hslArray, 'hsl').hsv();
},
});