1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 | (function (process,global){
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | ;(function(window, undefined) {
|
11 | 'use strict';
|
12 |
|
13 |
|
14 | var counter = 0;
|
15 |
|
16 |
|
17 | var doc = isHostType(window, 'document') && document;
|
18 |
|
19 |
|
20 | var freeDefine = typeof define == 'function' &&
|
21 | typeof define.amd == 'object' && define.amd && define;
|
22 |
|
23 |
|
24 | var freeExports = typeof exports == 'object' && exports &&
|
25 | (typeof global == 'object' && global && global == global.global && (window = global), exports);
|
26 |
|
27 |
|
28 | var freeRequire = typeof require == 'function' && require;
|
29 |
|
30 |
|
31 | var getAllKeys = Object.getOwnPropertyNames;
|
32 |
|
33 |
|
34 | var getDescriptor = Object.getOwnPropertyDescriptor;
|
35 |
|
36 |
|
37 | var hasOwnProperty = {}.hasOwnProperty;
|
38 |
|
39 |
|
40 | var isExtensible = Object.isExtensible || function() { return true; };
|
41 |
|
42 |
|
43 | var microtimeObject = req('microtime');
|
44 |
|
45 |
|
46 | var perfObject = isHostType(window, 'performance') && performance;
|
47 |
|
48 |
|
49 | var perfName = perfObject && (
|
50 | perfObject.now && 'now' ||
|
51 | perfObject.webkitNow && 'webkitNow'
|
52 | );
|
53 |
|
54 |
|
55 | var processObject = isHostType(window, 'process') && process;
|
56 |
|
57 |
|
58 | var propertyIsEnumerable = {}.propertyIsEnumerable;
|
59 |
|
60 |
|
61 | var setDescriptor = Object.defineProperty;
|
62 |
|
63 |
|
64 | var toString = {}.toString;
|
65 |
|
66 |
|
67 | var trash = doc && doc.createElement('div');
|
68 |
|
69 |
|
70 | var uid = 'uid' + (+new Date);
|
71 |
|
72 |
|
73 | var calledBy = {};
|
74 |
|
75 |
|
76 | var divisors = {
|
77 | '1': 4096,
|
78 | '2': 512,
|
79 | '3': 64,
|
80 | '4': 8,
|
81 | '5': 0
|
82 | };
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 | var tTable = {
|
89 | '1': 12.706,'2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447,
|
90 | '7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179,
|
91 | '13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101,
|
92 | '19': 2.093, '20': 2.086, '21': 2.08, '22': 2.074, '23': 2.069, '24': 2.064,
|
93 | '25': 2.06, '26': 2.056, '27': 2.052, '28': 2.048, '29': 2.045, '30': 2.042,
|
94 | 'infinity': 1.96
|
95 | };
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 | var uTable = {
|
102 | '5': [0, 1, 2],
|
103 | '6': [1, 2, 3, 5],
|
104 | '7': [1, 3, 5, 6, 8],
|
105 | '8': [2, 4, 6, 8, 10, 13],
|
106 | '9': [2, 4, 7, 10, 12, 15, 17],
|
107 | '10': [3, 5, 8, 11, 14, 17, 20, 23],
|
108 | '11': [3, 6, 9, 13, 16, 19, 23, 26, 30],
|
109 | '12': [4, 7, 11, 14, 18, 22, 26, 29, 33, 37],
|
110 | '13': [4, 8, 12, 16, 20, 24, 28, 33, 37, 41, 45],
|
111 | '14': [5, 9, 13, 17, 22, 26, 31, 36, 40, 45, 50, 55],
|
112 | '15': [5, 10, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64],
|
113 | '16': [6, 11, 15, 21, 26, 31, 37, 42, 47, 53, 59, 64, 70, 75],
|
114 | '17': [6, 11, 17, 22, 28, 34, 39, 45, 51, 57, 63, 67, 75, 81, 87],
|
115 | '18': [7, 12, 18, 24, 30, 36, 42, 48, 55, 61, 67, 74, 80, 86, 93, 99],
|
116 | '19': [7, 13, 19, 25, 32, 38, 45, 52, 58, 65, 72, 78, 85, 92, 99, 106, 113],
|
117 | '20': [8, 14, 20, 27, 34, 41, 48, 55, 62, 69, 76, 83, 90, 98, 105, 112, 119, 127],
|
118 | '21': [8, 15, 22, 29, 36, 43, 50, 58, 65, 73, 80, 88, 96, 103, 111, 119, 126, 134, 142],
|
119 | '22': [9, 16, 23, 30, 38, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 150, 158],
|
120 | '23': [9, 17, 24, 32, 40, 48, 56, 64, 73, 81, 89, 98, 106, 115, 123, 132, 140, 149, 157, 166, 175],
|
121 | '24': [10, 17, 25, 33, 42, 50, 59, 67, 76, 85, 94, 102, 111, 120, 129, 138, 147, 156, 165, 174, 183, 192],
|
122 | '25': [10, 18, 27, 35, 44, 53, 62, 71, 80, 89, 98, 107, 117, 126, 135, 145, 154, 163, 173, 182, 192, 201, 211],
|
123 | '26': [11, 19, 28, 37, 46, 55, 64, 74, 83, 93, 102, 112, 122, 132, 141, 151, 161, 171, 181, 191, 200, 210, 220, 230],
|
124 | '27': [11, 20, 29, 38, 48, 57, 67, 77, 87, 97, 107, 118, 125, 138, 147, 158, 168, 178, 188, 199, 209, 219, 230, 240, 250],
|
125 | '28': [12, 21, 30, 40, 50, 60, 70, 80, 90, 101, 111, 122, 132, 143, 154, 164, 175, 186, 196, 207, 218, 228, 239, 250, 261, 272],
|
126 | '29': [13, 22, 32, 42, 52, 62, 73, 83, 94, 105, 116, 127, 138, 149, 160, 171, 182, 193, 204, 215, 226, 238, 249, 260, 271, 282, 294],
|
127 | '30': [13, 23, 33, 43, 54, 65, 76, 87, 98, 109, 120, 131, 143, 154, 166, 177, 189, 200, 212, 223, 235, 247, 258, 270, 282, 293, 305, 317]
|
128 | };
|
129 |
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | var support = {};
|
138 |
|
139 | (function() {
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | support.air = isClassOf(window.runtime, 'ScriptBridgingProxyObject');
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | support.argumentsClass = isClassOf(arguments, 'Arguments');
|
156 |
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | support.browser = doc && isHostType(window, 'navigator');
|
164 |
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | support.charByIndex =
|
172 |
|
173 | ('x'[0] + Object('x')[0]) == 'xx';
|
174 |
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | support.charByOwnIndex =
|
182 |
|
183 |
|
184 | support.charByIndex && hasKey('x', '0');
|
185 |
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | support.java = isClassOf(window.java, 'JavaPackage');
|
193 |
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | support.timeout = isHostType(window, 'setTimeout') && isHostType(window, 'clearTimeout');
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | try {
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | support.decompilation = Function(
|
217 | 'return (' + (function(x) { return { 'x': '' + (1 + x) + '', 'y': 0 }; }) + ')'
|
218 | )()(0).x === '1';
|
219 | } catch(e) {
|
220 | support.decompilation = false;
|
221 | }
|
222 |
|
223 | |
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | try {
|
231 | var o = {};
|
232 | support.descriptors = (setDescriptor(o, o, o), 'value' in getDescriptor(o, o));
|
233 | } catch(e) {
|
234 | support.descriptors = false;
|
235 | }
|
236 |
|
237 | |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | try {
|
245 | support.getAllKeys = /\bvalueOf\b/.test(getAllKeys(Object.prototype));
|
246 | } catch(e) {
|
247 | support.getAllKeys = false;
|
248 | }
|
249 |
|
250 | |
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | support.iteratesOwnFirst = (function() {
|
258 | var props = [];
|
259 | function ctor() { this.x = 1; }
|
260 | ctor.prototype = { 'y': 1 };
|
261 | for (var prop in new ctor) { props.push(prop); }
|
262 | return props[0] == 'x';
|
263 | }());
|
264 |
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | try {
|
275 | support.nodeClass = ({ 'toString': 0 } + '', toString.call(doc || 0) != '[object Object]');
|
276 | } catch(e) {
|
277 | support.nodeClass = true;
|
278 | }
|
279 | }());
|
280 |
|
281 | |
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | var timer = {
|
288 |
|
289 | |
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | 'ns': Date,
|
297 |
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | 'start': null,
|
306 |
|
307 | |
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 | 'stop': null
|
315 | };
|
316 |
|
317 |
|
318 | var noArgumentsClass = !support.argumentsClass,
|
319 | noCharByIndex = !support.charByIndex,
|
320 | noCharByOwnIndex = !support.charByOwnIndex;
|
321 |
|
322 |
|
323 | var abs = Math.abs,
|
324 | floor = Math.floor,
|
325 | max = Math.max,
|
326 | min = Math.min,
|
327 | pow = Math.pow,
|
328 | sqrt = Math.sqrt;
|
329 |
|
330 |
|
331 |
|
332 | |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 | function Benchmark(name, fn, options) {
|
407 | var me = this;
|
408 |
|
409 |
|
410 | if (me == null || me.constructor != Benchmark) {
|
411 | return new Benchmark(name, fn, options);
|
412 | }
|
413 |
|
414 | if (isClassOf(name, 'Object')) {
|
415 |
|
416 | options = name;
|
417 | }
|
418 | else if (isClassOf(name, 'Function')) {
|
419 |
|
420 | options = fn;
|
421 | fn = name;
|
422 | }
|
423 | else if (isClassOf(fn, 'Object')) {
|
424 |
|
425 | options = fn;
|
426 | fn = null;
|
427 | me.name = name;
|
428 | }
|
429 | else {
|
430 |
|
431 | me.name = name;
|
432 | }
|
433 | setOptions(me, options);
|
434 | me.id || (me.id = ++counter);
|
435 | me.fn == null && (me.fn = fn);
|
436 | me.stats = deepClone(me.stats);
|
437 | me.times = deepClone(me.times);
|
438 | }
|
439 |
|
440 | |
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 | function Deferred(clone) {
|
448 | var me = this;
|
449 | if (me == null || me.constructor != Deferred) {
|
450 | return new Deferred(clone);
|
451 | }
|
452 | me.benchmark = clone;
|
453 | clock(me);
|
454 | }
|
455 |
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 | function Event(type) {
|
464 | var me = this;
|
465 | return (me == null || me.constructor != Event)
|
466 | ? new Event(type)
|
467 | : (type instanceof Event)
|
468 | ? type
|
469 | : extend(me, { 'timeStamp': +new Date }, typeof type == 'string' ? { 'type': type } : type);
|
470 | }
|
471 |
|
472 | |
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 | function Suite(name, options) {
|
510 | var me = this;
|
511 |
|
512 |
|
513 | if (me == null || me.constructor != Suite) {
|
514 | return new Suite(name, options);
|
515 | }
|
516 |
|
517 | if (isClassOf(name, 'Object')) {
|
518 |
|
519 | options = name;
|
520 | } else {
|
521 |
|
522 | me.name = name;
|
523 | }
|
524 | setOptions(me, options);
|
525 | }
|
526 |
|
527 |
|
528 |
|
529 | |
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | |
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 | function concat() {
|
559 | var value,
|
560 | j = -1,
|
561 | length = arguments.length,
|
562 | result = slice.call(this),
|
563 | index = result.length;
|
564 |
|
565 | while (++j < length) {
|
566 | value = arguments[j];
|
567 | if (isClassOf(value, 'Array')) {
|
568 | for (var k = 0, l = value.length; k < l; k++, index++) {
|
569 | if (k in value) {
|
570 | result[index] = value[k];
|
571 | }
|
572 | }
|
573 | } else {
|
574 | result[index++] = value;
|
575 | }
|
576 | }
|
577 | return result;
|
578 | }
|
579 |
|
580 | |
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 | function insert(start, deleteCount, elements) {
|
590 |
|
591 |
|
592 | var deleteEnd = start + deleteCount,
|
593 | elementCount = elements ? elements.length : 0,
|
594 | index = start - 1,
|
595 | length = start + elementCount,
|
596 | object = this,
|
597 | result = Array(deleteCount),
|
598 | tail = slice.call(object, deleteEnd);
|
599 |
|
600 |
|
601 | while (++index < deleteEnd) {
|
602 | if (index in object) {
|
603 | result[index - start] = object[index];
|
604 | delete object[index];
|
605 | }
|
606 | }
|
607 |
|
608 | index = start - 1;
|
609 | while (++index < length) {
|
610 | object[index] = elements[index - start];
|
611 | }
|
612 |
|
613 | start = index--;
|
614 | length = max(0, (object.length >>> 0) - deleteCount + elementCount);
|
615 | while (++index < length) {
|
616 | if ((index - start) in tail) {
|
617 | object[index] = tail[index - start];
|
618 | } else if (index in object) {
|
619 | delete object[index];
|
620 | }
|
621 | }
|
622 |
|
623 | deleteCount = deleteCount > elementCount ? deleteCount - elementCount : 0;
|
624 | while (deleteCount--) {
|
625 | index = length + deleteCount;
|
626 | if (index in object) {
|
627 | delete object[index];
|
628 | }
|
629 | }
|
630 | object.length = length;
|
631 | return result;
|
632 | }
|
633 |
|
634 | |
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 | function reverse() {
|
641 | var upperIndex,
|
642 | value,
|
643 | index = -1,
|
644 | object = Object(this),
|
645 | length = object.length >>> 0,
|
646 | middle = floor(length / 2);
|
647 |
|
648 | if (length > 1) {
|
649 | while (++index < middle) {
|
650 | upperIndex = length - index - 1;
|
651 | value = upperIndex in object ? object[upperIndex] : uid;
|
652 | if (index in object) {
|
653 | object[upperIndex] = object[index];
|
654 | } else {
|
655 | delete object[upperIndex];
|
656 | }
|
657 | if (value != uid) {
|
658 | object[index] = value;
|
659 | } else {
|
660 | delete object[index];
|
661 | }
|
662 | }
|
663 | }
|
664 | return object;
|
665 | }
|
666 |
|
667 | |
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 | function shift() {
|
674 | return insert.call(this, 0, 1)[0];
|
675 | }
|
676 |
|
677 | |
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | function slice(start, end) {
|
687 | var index = -1,
|
688 | object = Object(this),
|
689 | length = object.length >>> 0,
|
690 | result = [];
|
691 |
|
692 | start = toInteger(start);
|
693 | start = start < 0 ? max(length + start, 0) : min(start, length);
|
694 | start--;
|
695 | end = end == null ? length : toInteger(end);
|
696 | end = end < 0 ? max(length + end, 0) : min(end, length);
|
697 |
|
698 | while ((++index, ++start) < end) {
|
699 | if (start in object) {
|
700 | result[index] = object[start];
|
701 | }
|
702 | }
|
703 | return result;
|
704 | }
|
705 |
|
706 | |
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | function splice(start, deleteCount) {
|
717 | var object = Object(this),
|
718 | length = object.length >>> 0;
|
719 |
|
720 | start = toInteger(start);
|
721 | start = start < 0 ? max(length + start, 0) : min(start, length);
|
722 |
|
723 |
|
724 |
|
725 |
|
726 | deleteCount = arguments.length == 1
|
727 | ? length - start
|
728 | : min(max(toInteger(deleteCount), 0), length - start);
|
729 |
|
730 | return insert.call(object, start, deleteCount, slice.call(arguments, 2));
|
731 | }
|
732 |
|
733 | |
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | function toInteger(value) {
|
741 | value = +value;
|
742 | return value === 0 || !isFinite(value) ? value || 0 : value - (value % 1);
|
743 | }
|
744 |
|
745 | |
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 | function unshift() {
|
752 | var object = Object(this);
|
753 | insert.call(object, 0, 0, arguments);
|
754 | return object.length;
|
755 | }
|
756 |
|
757 |
|
758 |
|
759 | |
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | function bind(fn, thisArg) {
|
768 | return function() { fn.apply(thisArg, arguments); };
|
769 | }
|
770 |
|
771 | |
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 | function createFunction() {
|
780 |
|
781 | createFunction = function(args, body) {
|
782 | var result,
|
783 | anchor = freeDefine ? define.amd : Benchmark,
|
784 | prop = uid + 'createFunction';
|
785 |
|
786 | runScript((freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '=function(' + args + '){' + body + '}');
|
787 | result = anchor[prop];
|
788 | delete anchor[prop];
|
789 | return result;
|
790 | };
|
791 |
|
792 |
|
793 | createFunction = support.browser && (createFunction('', 'return"' + uid + '"') || noop)() == uid ? createFunction : Function;
|
794 | return createFunction.apply(null, arguments);
|
795 | }
|
796 |
|
797 | |
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 | function delay(bench, fn) {
|
805 | bench._timerId = setTimeout(fn, bench.delay * 1e3);
|
806 | }
|
807 |
|
808 | |
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 | function destroyElement(element) {
|
815 | trash.appendChild(element);
|
816 | trash.innerHTML = '';
|
817 | }
|
818 |
|
819 | |
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 | function forProps() {
|
830 | var forShadowed,
|
831 | skipSeen,
|
832 | forArgs = true,
|
833 | shadowed = ['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'];
|
834 |
|
835 | (function(enumFlag, key) {
|
836 |
|
837 | function Klass() { this.valueOf = 0; };
|
838 | Klass.prototype.valueOf = 0;
|
839 |
|
840 | for (key in new Klass) {
|
841 | enumFlag += key == 'valueOf' ? 1 : 0;
|
842 | }
|
843 |
|
844 | for (key in arguments) {
|
845 | key == '0' && (forArgs = false);
|
846 | }
|
847 |
|
848 |
|
849 | skipSeen = enumFlag == 2;
|
850 |
|
851 |
|
852 | forShadowed = !enumFlag;
|
853 | }(0));
|
854 |
|
855 |
|
856 | forProps = function(object, callback, options) {
|
857 | options || (options = {});
|
858 |
|
859 | var result = object;
|
860 | object = Object(object);
|
861 |
|
862 | var ctor,
|
863 | key,
|
864 | keys,
|
865 | skipCtor,
|
866 | done = !result,
|
867 | which = options.which,
|
868 | allFlag = which == 'all',
|
869 | index = -1,
|
870 | iteratee = object,
|
871 | length = object.length,
|
872 | ownFlag = allFlag || which == 'own',
|
873 | seen = {},
|
874 | skipProto = isClassOf(object, 'Function'),
|
875 | thisArg = options.bind;
|
876 |
|
877 | if (thisArg !== undefined) {
|
878 | callback = bind(callback, thisArg);
|
879 | }
|
880 |
|
881 | if (allFlag && support.getAllKeys) {
|
882 | for (index = 0, keys = getAllKeys(object), length = keys.length; index < length; index++) {
|
883 | key = keys[index];
|
884 | if (callback(object[key], key, object) === false) {
|
885 | break;
|
886 | }
|
887 | }
|
888 | }
|
889 |
|
890 | else {
|
891 | for (key in object) {
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 | if ((done =
|
898 | !(skipProto && key == 'prototype') &&
|
899 | !(skipSeen && (hasKey(seen, key) || !(seen[key] = true))) &&
|
900 | (!ownFlag || ownFlag && hasKey(object, key)) &&
|
901 | callback(object[key], key, object) === false)) {
|
902 | break;
|
903 | }
|
904 | }
|
905 |
|
906 | if (!done && (forArgs && isArguments(object) ||
|
907 | ((noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String') &&
|
908 | (iteratee = noCharByIndex ? object.split('') : object)))) {
|
909 | while (++index < length) {
|
910 | if ((done =
|
911 | callback(iteratee[index], String(index), object) === false)) {
|
912 | break;
|
913 | }
|
914 | }
|
915 | }
|
916 | if (!done && forShadowed) {
|
917 |
|
918 |
|
919 |
|
920 |
|
921 | ctor = object.constructor;
|
922 | skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor;
|
923 | for (index = 0; index < 7; index++) {
|
924 | key = shadowed[index];
|
925 | if (!(skipCtor && key == 'constructor') &&
|
926 | hasKey(object, key) &&
|
927 | callback(object[key], key, object) === false) {
|
928 | break;
|
929 | }
|
930 | }
|
931 | }
|
932 | }
|
933 | return result;
|
934 | };
|
935 | return forProps.apply(null, arguments);
|
936 | }
|
937 |
|
938 | |
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 | function getFirstArgument(fn) {
|
946 | return (!hasKey(fn, 'toString') &&
|
947 | (/^[\s(]*function[^(]*\(([^\s,)]+)/.exec(fn) || 0)[1]) || '';
|
948 | }
|
949 |
|
950 | |
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 | function getMean(sample) {
|
958 | return reduce(sample, function(sum, x) {
|
959 | return sum + x;
|
960 | }) / sample.length || 0;
|
961 | }
|
962 |
|
963 | |
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 | function getSource(fn, altSource) {
|
972 | var result = altSource;
|
973 | if (isStringable(fn)) {
|
974 | result = String(fn);
|
975 | } else if (support.decompilation) {
|
976 |
|
977 | result = (/^[^{]+\{([\s\S]*)}\s*$/.exec(fn) || 0)[1];
|
978 | }
|
979 |
|
980 | result = (result || '').replace(/^\s+|\s+$/g, '');
|
981 |
|
982 |
|
983 | return /^(?:\/\*+[\w|\W]*?\*\/|\/\/.*?[\n\r\u2028\u2029]|\s)*(["'])use strict\1;?$/.test(result)
|
984 | ? ''
|
985 | : result;
|
986 | }
|
987 |
|
988 | |
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 | function isArguments() {
|
996 |
|
997 | isArguments = function(value) {
|
998 | return toString.call(value) == '[object Arguments]';
|
999 | };
|
1000 | if (noArgumentsClass) {
|
1001 | isArguments = function(value) {
|
1002 | return hasKey(value, 'callee') &&
|
1003 | !(propertyIsEnumerable && propertyIsEnumerable.call(value, 'callee'));
|
1004 | };
|
1005 | }
|
1006 | return isArguments(arguments[0]);
|
1007 | }
|
1008 |
|
1009 | |
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 | function isClassOf(value, name) {
|
1018 | return value != null && toString.call(value) == '[object ' + name + ']';
|
1019 | }
|
1020 |
|
1021 | |
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 | function isHostType(object, property) {
|
1032 | var type = object != null ? typeof object[property] : 'number';
|
1033 | return !/^(?:boolean|number|string|undefined)$/.test(type) &&
|
1034 | (type == 'object' ? !!object[property] : true);
|
1035 | }
|
1036 |
|
1037 | |
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | function isPlainObject(value) {
|
1047 |
|
1048 | var result = false;
|
1049 | if (!(value && typeof value == 'object') || (noArgumentsClass && isArguments(value))) {
|
1050 | return result;
|
1051 | }
|
1052 |
|
1053 |
|
1054 |
|
1055 | var ctor = value.constructor;
|
1056 | if ((support.nodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string')) &&
|
1057 | (!isClassOf(ctor, 'Function') || ctor instanceof ctor)) {
|
1058 |
|
1059 |
|
1060 |
|
1061 | if (support.iteratesOwnFirst) {
|
1062 | forProps(value, function(subValue, subKey) {
|
1063 | result = subKey;
|
1064 | });
|
1065 | return result === false || hasKey(value, result);
|
1066 | }
|
1067 |
|
1068 |
|
1069 |
|
1070 | forProps(value, function(subValue, subKey) {
|
1071 | result = !hasKey(value, subKey);
|
1072 | return false;
|
1073 | });
|
1074 | return result === false;
|
1075 | }
|
1076 | return result;
|
1077 | }
|
1078 |
|
1079 | |
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 | function isStringable(value) {
|
1087 | return hasKey(value, 'toString') || isClassOf(value, 'String');
|
1088 | }
|
1089 |
|
1090 | |
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 | function methodize(fn) {
|
1099 | return function() {
|
1100 | var args = [this];
|
1101 | args.push.apply(args, arguments);
|
1102 | return fn.apply(null, args);
|
1103 | };
|
1104 | }
|
1105 |
|
1106 | |
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 | function noop() {
|
1112 |
|
1113 | }
|
1114 |
|
1115 | |
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 | function req(id) {
|
1123 | try {
|
1124 | var result = freeExports && freeRequire(id);
|
1125 | } catch(e) { }
|
1126 | return result || null;
|
1127 | }
|
1128 |
|
1129 | |
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 | function runScript(code) {
|
1136 | var anchor = freeDefine ? define.amd : Benchmark,
|
1137 | script = doc.createElement('script'),
|
1138 | sibling = doc.getElementsByTagName('script')[0],
|
1139 | parent = sibling.parentNode,
|
1140 | prop = uid + 'runScript',
|
1141 | prefix = '(' + (freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '||function(){})();';
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 | try {
|
1147 |
|
1148 |
|
1149 | script.appendChild(doc.createTextNode(prefix + code));
|
1150 | anchor[prop] = function() { destroyElement(script); };
|
1151 | } catch(e) {
|
1152 | parent = parent.cloneNode(false);
|
1153 | sibling = null;
|
1154 | script.text = code;
|
1155 | }
|
1156 | parent.insertBefore(script, sibling);
|
1157 | delete anchor[prop];
|
1158 | }
|
1159 |
|
1160 | |
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 | function setOptions(bench, options) {
|
1168 | options = extend({}, bench.constructor.options, options);
|
1169 | bench.options = forOwn(options, function(value, key) {
|
1170 | if (value != null) {
|
1171 |
|
1172 | if (/^on[A-Z]/.test(key)) {
|
1173 | forEach(key.split(' '), function(key) {
|
1174 | bench.on(key.slice(2).toLowerCase(), value);
|
1175 | });
|
1176 | } else if (!hasKey(bench, key)) {
|
1177 | bench[key] = deepClone(value);
|
1178 | }
|
1179 | }
|
1180 | });
|
1181 | }
|
1182 |
|
1183 |
|
1184 |
|
1185 | |
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 | function resolve() {
|
1191 | var me = this,
|
1192 | clone = me.benchmark,
|
1193 | bench = clone._original;
|
1194 |
|
1195 | if (bench.aborted) {
|
1196 |
|
1197 | me.teardown();
|
1198 | clone.running = false;
|
1199 | cycle(me);
|
1200 | }
|
1201 | else if (++me.cycles < clone.count) {
|
1202 |
|
1203 | if (support.timeout) {
|
1204 |
|
1205 | setTimeout(function() { clone.compiled.call(me, timer); }, 0);
|
1206 | } else {
|
1207 | clone.compiled.call(me, timer);
|
1208 | }
|
1209 | }
|
1210 | else {
|
1211 | timer.stop(me);
|
1212 | me.teardown();
|
1213 | delay(clone, function() { cycle(me); });
|
1214 | }
|
1215 | }
|
1216 |
|
1217 |
|
1218 |
|
1219 | |
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 | function deepClone(value) {
|
1228 | var accessor,
|
1229 | circular,
|
1230 | clone,
|
1231 | ctor,
|
1232 | descriptor,
|
1233 | extensible,
|
1234 | key,
|
1235 | length,
|
1236 | markerKey,
|
1237 | parent,
|
1238 | result,
|
1239 | source,
|
1240 | subIndex,
|
1241 | data = { 'value': value },
|
1242 | index = 0,
|
1243 | marked = [],
|
1244 | queue = { 'length': 0 },
|
1245 | unmarked = [];
|
1246 |
|
1247 | |
1248 |
|
1249 |
|
1250 | function Marker(object) {
|
1251 | this.raw = object;
|
1252 | }
|
1253 |
|
1254 | |
1255 |
|
1256 |
|
1257 | function forPropsCallback(subValue, subKey) {
|
1258 |
|
1259 | if (subValue && subValue.constructor == Marker) {
|
1260 | return;
|
1261 | }
|
1262 |
|
1263 | if (subValue === Object(subValue)) {
|
1264 | queue[queue.length++] = { 'key': subKey, 'parent': clone, 'source': value };
|
1265 | }
|
1266 |
|
1267 | else {
|
1268 | try {
|
1269 |
|
1270 | clone[subKey] = subValue;
|
1271 | } catch(e) { }
|
1272 | }
|
1273 | }
|
1274 |
|
1275 | |
1276 |
|
1277 |
|
1278 | function getMarkerKey(object) {
|
1279 |
|
1280 | var result = uid;
|
1281 | while (object[result] && object[result].constructor != Marker) {
|
1282 | result += 1;
|
1283 | }
|
1284 | return result;
|
1285 | }
|
1286 |
|
1287 | do {
|
1288 | key = data.key;
|
1289 | parent = data.parent;
|
1290 | source = data.source;
|
1291 | clone = value = source ? source[key] : data.value;
|
1292 | accessor = circular = descriptor = false;
|
1293 |
|
1294 |
|
1295 |
|
1296 | if (value === Object(value)) {
|
1297 |
|
1298 | if (isClassOf(value.deepClone, 'Function')) {
|
1299 | clone = value.deepClone();
|
1300 | } else {
|
1301 | ctor = value.constructor;
|
1302 | switch (toString.call(value)) {
|
1303 | case '[object Array]':
|
1304 | clone = new ctor(value.length);
|
1305 | break;
|
1306 |
|
1307 | case '[object Boolean]':
|
1308 | clone = new ctor(value == true);
|
1309 | break;
|
1310 |
|
1311 | case '[object Date]':
|
1312 | clone = new ctor(+value);
|
1313 | break;
|
1314 |
|
1315 | case '[object Object]':
|
1316 | isPlainObject(value) && (clone = {});
|
1317 | break;
|
1318 |
|
1319 | case '[object Number]':
|
1320 | case '[object String]':
|
1321 | clone = new ctor(value);
|
1322 | break;
|
1323 |
|
1324 | case '[object RegExp]':
|
1325 | clone = ctor(value.source,
|
1326 | (value.global ? 'g' : '') +
|
1327 | (value.ignoreCase ? 'i' : '') +
|
1328 | (value.multiline ? 'm' : ''));
|
1329 | }
|
1330 | }
|
1331 |
|
1332 |
|
1333 | if (clone && clone != value &&
|
1334 | !(descriptor = source && support.descriptors && getDescriptor(source, key),
|
1335 | accessor = descriptor && (descriptor.get || descriptor.set))) {
|
1336 |
|
1337 | if ((extensible = isExtensible(value))) {
|
1338 | markerKey = getMarkerKey(value);
|
1339 | if (value[markerKey]) {
|
1340 | circular = clone = value[markerKey].raw;
|
1341 | }
|
1342 | } else {
|
1343 |
|
1344 | for (subIndex = 0, length = unmarked.length; subIndex < length; subIndex++) {
|
1345 | data = unmarked[subIndex];
|
1346 | if (data.object === value) {
|
1347 | circular = clone = data.clone;
|
1348 | break;
|
1349 | }
|
1350 | }
|
1351 | }
|
1352 | if (!circular) {
|
1353 |
|
1354 | if (extensible) {
|
1355 | value[markerKey] = new Marker(clone);
|
1356 | marked.push({ 'key': markerKey, 'object': value });
|
1357 | } else {
|
1358 |
|
1359 | unmarked.push({ 'clone': clone, 'object': value });
|
1360 | }
|
1361 |
|
1362 | forProps(value, forPropsCallback, { 'which': 'all' });
|
1363 | }
|
1364 | }
|
1365 | }
|
1366 | if (parent) {
|
1367 |
|
1368 | if (accessor || (descriptor && !(descriptor.configurable && descriptor.enumerable && descriptor.writable))) {
|
1369 | if ('value' in descriptor) {
|
1370 | descriptor.value = clone;
|
1371 | }
|
1372 | setDescriptor(parent, key, descriptor);
|
1373 | }
|
1374 |
|
1375 | else {
|
1376 | parent[key] = clone;
|
1377 | }
|
1378 | } else {
|
1379 | result = clone;
|
1380 | }
|
1381 | } while ((data = queue[index++]));
|
1382 |
|
1383 |
|
1384 | for (index = 0, length = marked.length; index < length; index++) {
|
1385 | data = marked[index];
|
1386 | delete data.object[data.key];
|
1387 | }
|
1388 | return result;
|
1389 | }
|
1390 |
|
1391 | |
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 | function each(object, callback, thisArg) {
|
1403 | var result = object;
|
1404 | object = Object(object);
|
1405 |
|
1406 | var fn = callback,
|
1407 | index = -1,
|
1408 | length = object.length,
|
1409 | isSnapshot = !!(object.snapshotItem && (length = object.snapshotLength)),
|
1410 | isSplittable = (noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String'),
|
1411 | isConvertable = isSnapshot || isSplittable || 'item' in object,
|
1412 | origObject = object;
|
1413 |
|
1414 |
|
1415 | if (length === length >>> 0) {
|
1416 | if (isConvertable) {
|
1417 |
|
1418 | callback = function(value, index) {
|
1419 | return fn.call(this, value, index, origObject);
|
1420 | };
|
1421 |
|
1422 | if (isSplittable) {
|
1423 | object = object.split('');
|
1424 | } else {
|
1425 | object = [];
|
1426 | while (++index < length) {
|
1427 |
|
1428 | object[index] = isSnapshot ? result.snapshotItem(index) : result[index];
|
1429 | }
|
1430 | }
|
1431 | }
|
1432 | forEach(object, callback, thisArg);
|
1433 | } else {
|
1434 | forOwn(object, callback, thisArg);
|
1435 | }
|
1436 | return result;
|
1437 | }
|
1438 |
|
1439 | |
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 | function extend(destination, source) {
|
1449 |
|
1450 |
|
1451 | var result = destination;
|
1452 | delete arguments[0];
|
1453 |
|
1454 | forEach(arguments, function(source) {
|
1455 | forProps(source, function(value, key) {
|
1456 | result[key] = value;
|
1457 | });
|
1458 | });
|
1459 | return result;
|
1460 | }
|
1461 |
|
1462 | |
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 | function filter(array, callback, thisArg) {
|
1488 | var result;
|
1489 |
|
1490 | if (callback == 'successful') {
|
1491 |
|
1492 | callback = function(bench) { return bench.cycles && isFinite(bench.hz); };
|
1493 | }
|
1494 | else if (callback == 'fastest' || callback == 'slowest') {
|
1495 |
|
1496 | result = filter(array, 'successful').sort(function(a, b) {
|
1497 | a = a.stats; b = b.stats;
|
1498 | return (a.mean + a.moe > b.mean + b.moe ? 1 : -1) * (callback == 'fastest' ? 1 : -1);
|
1499 | });
|
1500 | result = filter(result, function(bench) {
|
1501 | return result[0].compare(bench) == 0;
|
1502 | });
|
1503 | }
|
1504 | return result || reduce(array, function(result, value, index) {
|
1505 | return callback.call(thisArg, value, index, array) ? (result.push(value), result) : result;
|
1506 | }, []);
|
1507 | }
|
1508 |
|
1509 | |
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 | function forEach(array, callback, thisArg) {
|
1521 | var index = -1,
|
1522 | length = (array = Object(array)).length >>> 0;
|
1523 |
|
1524 | if (thisArg !== undefined) {
|
1525 | callback = bind(callback, thisArg);
|
1526 | }
|
1527 | while (++index < length) {
|
1528 | if (index in array &&
|
1529 | callback(array[index], index, array) === false) {
|
1530 | break;
|
1531 | }
|
1532 | }
|
1533 | return array;
|
1534 | }
|
1535 |
|
1536 | |
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 | function forOwn(object, callback, thisArg) {
|
1548 | return forProps(object, callback, { 'bind': thisArg, 'which': 'own' });
|
1549 | }
|
1550 |
|
1551 | |
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 | function formatNumber(number) {
|
1560 | number = String(number).split('.');
|
1561 | return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') +
|
1562 | (number[1] ? '.' + number[1] : '');
|
1563 | }
|
1564 |
|
1565 | |
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 | function hasKey() {
|
1575 |
|
1576 | hasKey = function(object, key) {
|
1577 | var parent = object != null && (object.constructor || Object).prototype;
|
1578 | return !!parent && key in Object(object) && !(key in parent && object[key] === parent[key]);
|
1579 | };
|
1580 |
|
1581 | if (isClassOf(hasOwnProperty, 'Function')) {
|
1582 | hasKey = function(object, key) {
|
1583 | return object != null && hasOwnProperty.call(object, key);
|
1584 | };
|
1585 | }
|
1586 |
|
1587 | else if ({}.__proto__ == Object.prototype) {
|
1588 | hasKey = function(object, key) {
|
1589 | var result = false;
|
1590 | if (object != null) {
|
1591 | object = Object(object);
|
1592 | object.__proto__ = [object.__proto__, object.__proto__ = null, result = key in object][0];
|
1593 | }
|
1594 | return result;
|
1595 | };
|
1596 | }
|
1597 | return hasKey.apply(this, arguments);
|
1598 | }
|
1599 |
|
1600 | |
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 | function indexOf(array, value, fromIndex) {
|
1611 | var index = toInteger(fromIndex),
|
1612 | length = (array = Object(array)).length >>> 0;
|
1613 |
|
1614 | index = (index < 0 ? max(0, length + index) : index) - 1;
|
1615 | while (++index < length) {
|
1616 | if (index in array && value === array[index]) {
|
1617 | return index;
|
1618 | }
|
1619 | }
|
1620 | return -1;
|
1621 | }
|
1622 |
|
1623 | |
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 | function interpolate(string, object) {
|
1633 | forOwn(object, function(value, key) {
|
1634 |
|
1635 | string = string.replace(RegExp('#\\{' + key.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + '\\}', 'g'), value);
|
1636 | });
|
1637 | return string;
|
1638 | }
|
1639 |
|
1640 | |
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 | function invoke(benches, name) {
|
1680 | var args,
|
1681 | bench,
|
1682 | queued,
|
1683 | index = -1,
|
1684 | eventProps = { 'currentTarget': benches },
|
1685 | options = { 'onStart': noop, 'onCycle': noop, 'onComplete': noop },
|
1686 | result = map(benches, function(bench) { return bench; });
|
1687 |
|
1688 | |
1689 |
|
1690 |
|
1691 | function execute() {
|
1692 | var listeners,
|
1693 | async = isAsync(bench);
|
1694 |
|
1695 | if (async) {
|
1696 |
|
1697 | bench.on('complete', getNext);
|
1698 | listeners = bench.events.complete;
|
1699 | listeners.splice(0, 0, listeners.pop());
|
1700 | }
|
1701 |
|
1702 | result[index] = isClassOf(bench && bench[name], 'Function') ? bench[name].apply(bench, args) : undefined;
|
1703 |
|
1704 | return !async && getNext();
|
1705 | }
|
1706 |
|
1707 | |
1708 |
|
1709 |
|
1710 | function getNext(event) {
|
1711 | var cycleEvent,
|
1712 | last = bench,
|
1713 | async = isAsync(last);
|
1714 |
|
1715 | if (async) {
|
1716 | last.off('complete', getNext);
|
1717 | last.emit('complete');
|
1718 | }
|
1719 |
|
1720 | eventProps.type = 'cycle';
|
1721 | eventProps.target = last;
|
1722 | cycleEvent = Event(eventProps);
|
1723 | options.onCycle.call(benches, cycleEvent);
|
1724 |
|
1725 |
|
1726 | if (!cycleEvent.aborted && raiseIndex() !== false) {
|
1727 | bench = queued ? benches[0] : result[index];
|
1728 | if (isAsync(bench)) {
|
1729 | delay(bench, execute);
|
1730 | }
|
1731 | else if (async) {
|
1732 |
|
1733 | while (execute()) { }
|
1734 | }
|
1735 | else {
|
1736 |
|
1737 | return true;
|
1738 | }
|
1739 | } else {
|
1740 |
|
1741 | eventProps.type = 'complete';
|
1742 | options.onComplete.call(benches, Event(eventProps));
|
1743 | }
|
1744 |
|
1745 |
|
1746 |
|
1747 | if (event) {
|
1748 | event.aborted = true;
|
1749 | } else {
|
1750 | return false;
|
1751 | }
|
1752 | }
|
1753 |
|
1754 | |
1755 |
|
1756 |
|
1757 | function isAsync(object) {
|
1758 |
|
1759 | var async = args[0] && args[0].async;
|
1760 | return Object(object).constructor == Benchmark && name == 'run' &&
|
1761 | ((async == null ? object.options.async : async) && support.timeout || object.defer);
|
1762 | }
|
1763 |
|
1764 | |
1765 |
|
1766 |
|
1767 | function raiseIndex() {
|
1768 | var length = result.length;
|
1769 | if (queued) {
|
1770 |
|
1771 | do {
|
1772 | ++index > 0 && shift.call(benches);
|
1773 | } while ((length = benches.length) && !('0' in benches));
|
1774 | }
|
1775 | else {
|
1776 | while (++index < length && !(index in result)) { }
|
1777 | }
|
1778 |
|
1779 | return (queued ? length : index < length) ? index : (index = false);
|
1780 | }
|
1781 |
|
1782 |
|
1783 | if (isClassOf(name, 'String')) {
|
1784 |
|
1785 | args = slice.call(arguments, 2);
|
1786 | } else {
|
1787 |
|
1788 | options = extend(options, name);
|
1789 | name = options.name;
|
1790 | args = isClassOf(args = 'args' in options ? options.args : [], 'Array') ? args : [args];
|
1791 | queued = options.queued;
|
1792 | }
|
1793 |
|
1794 |
|
1795 | if (raiseIndex() !== false) {
|
1796 |
|
1797 | bench = result[index];
|
1798 | eventProps.type = 'start';
|
1799 | eventProps.target = bench;
|
1800 | options.onStart.call(benches, Event(eventProps));
|
1801 |
|
1802 |
|
1803 | if (benches.aborted && benches.constructor == Suite && name == 'run') {
|
1804 |
|
1805 | eventProps.type = 'cycle';
|
1806 | options.onCycle.call(benches, Event(eventProps));
|
1807 |
|
1808 | eventProps.type = 'complete';
|
1809 | options.onComplete.call(benches, Event(eventProps));
|
1810 | }
|
1811 |
|
1812 | else {
|
1813 | if (isAsync(bench)) {
|
1814 | delay(bench, execute);
|
1815 | } else {
|
1816 | while (execute()) { }
|
1817 | }
|
1818 | }
|
1819 | }
|
1820 | return result;
|
1821 | }
|
1822 |
|
1823 | |
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 | function join(object, separator1, separator2) {
|
1834 | var result = [],
|
1835 | length = (object = Object(object)).length,
|
1836 | arrayLike = length === length >>> 0;
|
1837 |
|
1838 | separator2 || (separator2 = ': ');
|
1839 | each(object, function(value, key) {
|
1840 | result.push(arrayLike ? value : key + separator2 + value);
|
1841 | });
|
1842 | return result.join(separator1 || ',');
|
1843 | }
|
1844 |
|
1845 | |
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 | function map(array, callback, thisArg) {
|
1856 | return reduce(array, function(result, value, index) {
|
1857 | result[index] = callback.call(thisArg, value, index, array);
|
1858 | return result;
|
1859 | }, Array(Object(array).length >>> 0));
|
1860 | }
|
1861 |
|
1862 | |
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 | function pluck(array, property) {
|
1872 | return map(array, function(object) {
|
1873 | return object == null ? undefined : object[property];
|
1874 | });
|
1875 | }
|
1876 |
|
1877 | |
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 | function reduce(array, callback, accumulator) {
|
1888 | var noaccum = arguments.length < 3;
|
1889 | forEach(array, function(value, index) {
|
1890 | accumulator = noaccum ? (noaccum = false, value) : callback(accumulator, value, index, array);
|
1891 | });
|
1892 | return accumulator;
|
1893 | }
|
1894 |
|
1895 |
|
1896 |
|
1897 | |
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 |
|
1904 | function abortSuite() {
|
1905 | var event,
|
1906 | me = this,
|
1907 | resetting = calledBy.resetSuite;
|
1908 |
|
1909 | if (me.running) {
|
1910 | event = Event('abort');
|
1911 | me.emit(event);
|
1912 | if (!event.cancelled || resetting) {
|
1913 |
|
1914 | calledBy.abortSuite = true;
|
1915 | me.reset();
|
1916 | delete calledBy.abortSuite;
|
1917 |
|
1918 | if (!resetting) {
|
1919 | me.aborted = true;
|
1920 | invoke(me, 'abort');
|
1921 | }
|
1922 | }
|
1923 | }
|
1924 | return me;
|
1925 | }
|
1926 |
|
1927 | |
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 | function add(name, fn, options) {
|
1965 | var me = this,
|
1966 | bench = Benchmark(name, fn, options),
|
1967 | event = Event({ 'type': 'add', 'target': bench });
|
1968 |
|
1969 | if (me.emit(event), !event.cancelled) {
|
1970 | me.push(bench);
|
1971 | }
|
1972 | return me;
|
1973 | }
|
1974 |
|
1975 | |
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 | function cloneSuite(options) {
|
1984 | var me = this,
|
1985 | result = new me.constructor(extend({}, me.options, options));
|
1986 |
|
1987 |
|
1988 | forOwn(me, function(value, key) {
|
1989 | if (!hasKey(result, key)) {
|
1990 | result[key] = value && isClassOf(value.clone, 'Function')
|
1991 | ? value.clone()
|
1992 | : deepClone(value);
|
1993 | }
|
1994 | });
|
1995 | return result;
|
1996 | }
|
1997 |
|
1998 | |
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 | function filterSuite(callback) {
|
2007 | var me = this,
|
2008 | result = new me.constructor;
|
2009 |
|
2010 | result.push.apply(result, filter(me, callback));
|
2011 | return result;
|
2012 | }
|
2013 |
|
2014 | |
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | function resetSuite() {
|
2022 | var event,
|
2023 | me = this,
|
2024 | aborting = calledBy.abortSuite;
|
2025 |
|
2026 | if (me.running && !aborting) {
|
2027 |
|
2028 | calledBy.resetSuite = true;
|
2029 | me.abort();
|
2030 | delete calledBy.resetSuite;
|
2031 | }
|
2032 |
|
2033 | else if ((me.aborted || me.running) &&
|
2034 | (me.emit(event = Event('reset')), !event.cancelled)) {
|
2035 | me.running = false;
|
2036 | if (!aborting) {
|
2037 | invoke(me, 'reset');
|
2038 | }
|
2039 | }
|
2040 | return me;
|
2041 | }
|
2042 |
|
2043 | |
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 | function runSuite(options) {
|
2059 | var me = this;
|
2060 |
|
2061 | me.reset();
|
2062 | me.running = true;
|
2063 | options || (options = {});
|
2064 |
|
2065 | invoke(me, {
|
2066 | 'name': 'run',
|
2067 | 'args': options,
|
2068 | 'queued': options.queued,
|
2069 | 'onStart': function(event) {
|
2070 | me.emit(event);
|
2071 | },
|
2072 | 'onCycle': function(event) {
|
2073 | var bench = event.target;
|
2074 | if (bench.error) {
|
2075 | me.emit({ 'type': 'error', 'target': bench });
|
2076 | }
|
2077 | me.emit(event);
|
2078 | event.aborted = me.aborted;
|
2079 | },
|
2080 | 'onComplete': function(event) {
|
2081 | me.running = false;
|
2082 | me.emit(event);
|
2083 | }
|
2084 | });
|
2085 | return me;
|
2086 | }
|
2087 |
|
2088 |
|
2089 |
|
2090 | |
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 | function emit(type) {
|
2098 | var listeners,
|
2099 | me = this,
|
2100 | event = Event(type),
|
2101 | events = me.events,
|
2102 | args = (arguments[0] = event, arguments);
|
2103 |
|
2104 | event.currentTarget || (event.currentTarget = me);
|
2105 | event.target || (event.target = me);
|
2106 | delete event.result;
|
2107 |
|
2108 | if (events && (listeners = hasKey(events, event.type) && events[event.type])) {
|
2109 | forEach(listeners.slice(), function(listener) {
|
2110 | if ((event.result = listener.apply(me, args)) === false) {
|
2111 | event.cancelled = true;
|
2112 | }
|
2113 | return !event.aborted;
|
2114 | });
|
2115 | }
|
2116 | return event.result;
|
2117 | }
|
2118 |
|
2119 | |
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 | function listeners(type) {
|
2128 | var me = this,
|
2129 | events = me.events || (me.events = {});
|
2130 |
|
2131 | return hasKey(events, type) ? events[type] : (events[type] = []);
|
2132 | }
|
2133 |
|
2134 | |
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 | function off(type, listener) {
|
2161 | var me = this,
|
2162 | events = me.events;
|
2163 |
|
2164 | events && each(type ? type.split(' ') : events, function(listeners, type) {
|
2165 | var index;
|
2166 | if (typeof listeners == 'string') {
|
2167 | type = listeners;
|
2168 | listeners = hasKey(events, type) && events[type];
|
2169 | }
|
2170 | if (listeners) {
|
2171 | if (listener) {
|
2172 | index = indexOf(listeners, listener);
|
2173 | if (index > -1) {
|
2174 | listeners.splice(index, 1);
|
2175 | }
|
2176 | } else {
|
2177 | listeners.length = 0;
|
2178 | }
|
2179 | }
|
2180 | });
|
2181 | return me;
|
2182 | }
|
2183 |
|
2184 | |
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 | function on(type, listener) {
|
2200 | var me = this,
|
2201 | events = me.events || (me.events = {});
|
2202 |
|
2203 | forEach(type.split(' '), function(type) {
|
2204 | (hasKey(events, type)
|
2205 | ? events[type]
|
2206 | : (events[type] = [])
|
2207 | ).push(listener);
|
2208 | });
|
2209 | return me;
|
2210 | }
|
2211 |
|
2212 |
|
2213 |
|
2214 | |
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 | function abort() {
|
2221 | var event,
|
2222 | me = this,
|
2223 | resetting = calledBy.reset;
|
2224 |
|
2225 | if (me.running) {
|
2226 | event = Event('abort');
|
2227 | me.emit(event);
|
2228 | if (!event.cancelled || resetting) {
|
2229 |
|
2230 | calledBy.abort = true;
|
2231 | me.reset();
|
2232 | delete calledBy.abort;
|
2233 |
|
2234 | if (support.timeout) {
|
2235 | clearTimeout(me._timerId);
|
2236 | delete me._timerId;
|
2237 | }
|
2238 | if (!resetting) {
|
2239 | me.aborted = true;
|
2240 | me.running = false;
|
2241 | }
|
2242 | }
|
2243 | }
|
2244 | return me;
|
2245 | }
|
2246 |
|
2247 | |
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | function clone(options) {
|
2260 | var me = this,
|
2261 | result = new me.constructor(extend({}, me, options));
|
2262 |
|
2263 |
|
2264 | result.options = extend({}, me.options, options);
|
2265 |
|
2266 |
|
2267 | forOwn(me, function(value, key) {
|
2268 | if (!hasKey(result, key)) {
|
2269 | result[key] = deepClone(value);
|
2270 | }
|
2271 | });
|
2272 | return result;
|
2273 | }
|
2274 |
|
2275 | |
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 | function compare(other) {
|
2283 | var critical,
|
2284 | zStat,
|
2285 | me = this,
|
2286 | sample1 = me.stats.sample,
|
2287 | sample2 = other.stats.sample,
|
2288 | size1 = sample1.length,
|
2289 | size2 = sample2.length,
|
2290 | maxSize = max(size1, size2),
|
2291 | minSize = min(size1, size2),
|
2292 | u1 = getU(sample1, sample2),
|
2293 | u2 = getU(sample2, sample1),
|
2294 | u = min(u1, u2);
|
2295 |
|
2296 | function getScore(xA, sampleB) {
|
2297 | return reduce(sampleB, function(total, xB) {
|
2298 | return total + (xB > xA ? 0 : xB < xA ? 1 : 0.5);
|
2299 | }, 0);
|
2300 | }
|
2301 |
|
2302 | function getU(sampleA, sampleB) {
|
2303 | return reduce(sampleA, function(total, xA) {
|
2304 | return total + getScore(xA, sampleB);
|
2305 | }, 0);
|
2306 | }
|
2307 |
|
2308 | function getZ(u) {
|
2309 | return (u - ((size1 * size2) / 2)) / sqrt((size1 * size2 * (size1 + size2 + 1)) / 12);
|
2310 | }
|
2311 |
|
2312 |
|
2313 | if (me == other) {
|
2314 | return 0;
|
2315 | }
|
2316 |
|
2317 |
|
2318 | if (size1 + size2 > 30) {
|
2319 |
|
2320 |
|
2321 | zStat = getZ(u);
|
2322 | return abs(zStat) > 1.96 ? (zStat > 0 ? -1 : 1) : 0;
|
2323 | }
|
2324 |
|
2325 |
|
2326 | critical = maxSize < 5 || minSize < 3 ? 0 : uTable[maxSize][minSize - 3];
|
2327 | return u <= critical ? (u == u1 ? 1 : -1) : 0;
|
2328 | }
|
2329 |
|
2330 | |
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 | function reset() {
|
2337 | var data,
|
2338 | event,
|
2339 | me = this,
|
2340 | index = 0,
|
2341 | changes = { 'length': 0 },
|
2342 | queue = { 'length': 0 };
|
2343 |
|
2344 | if (me.running && !calledBy.abort) {
|
2345 |
|
2346 | calledBy.reset = true;
|
2347 | me.abort();
|
2348 | delete calledBy.reset;
|
2349 | }
|
2350 | else {
|
2351 |
|
2352 |
|
2353 | data = { 'destination': me, 'source': extend({}, me.constructor.prototype, me.options) };
|
2354 | do {
|
2355 | forOwn(data.source, function(value, key) {
|
2356 | var changed,
|
2357 | destination = data.destination,
|
2358 | currValue = destination[key];
|
2359 |
|
2360 | if (value && typeof value == 'object') {
|
2361 | if (isClassOf(value, 'Array')) {
|
2362 |
|
2363 | if (!isClassOf(currValue, 'Array')) {
|
2364 | changed = currValue = [];
|
2365 | }
|
2366 |
|
2367 | if (currValue.length != value.length) {
|
2368 | changed = currValue = currValue.slice(0, value.length);
|
2369 | currValue.length = value.length;
|
2370 | }
|
2371 | }
|
2372 |
|
2373 | else if (!currValue || typeof currValue != 'object') {
|
2374 | changed = currValue = {};
|
2375 | }
|
2376 |
|
2377 | if (changed) {
|
2378 | changes[changes.length++] = { 'destination': destination, 'key': key, 'value': currValue };
|
2379 | }
|
2380 | queue[queue.length++] = { 'destination': currValue, 'source': value };
|
2381 | }
|
2382 |
|
2383 | else if (value !== currValue && !(value == null || isClassOf(value, 'Function'))) {
|
2384 | changes[changes.length++] = { 'destination': destination, 'key': key, 'value': value };
|
2385 | }
|
2386 | });
|
2387 | }
|
2388 | while ((data = queue[index++]));
|
2389 |
|
2390 |
|
2391 | if (changes.length && (me.emit(event = Event('reset')), !event.cancelled)) {
|
2392 | forEach(changes, function(data) {
|
2393 | data.destination[data.key] = data.value;
|
2394 | });
|
2395 | }
|
2396 | }
|
2397 | return me;
|
2398 | }
|
2399 |
|
2400 | |
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 | function toStringBench() {
|
2408 | var me = this,
|
2409 | error = me.error,
|
2410 | hz = me.hz,
|
2411 | id = me.id,
|
2412 | stats = me.stats,
|
2413 | size = stats.sample.length,
|
2414 | pm = support.java ? '+/-' : '\xb1',
|
2415 | result = me.name || (isNaN(id) ? id : '<Test #' + id + '>');
|
2416 |
|
2417 | if (error) {
|
2418 | result += ': ' + join(error);
|
2419 | } else {
|
2420 | result += ' x ' + formatNumber(hz.toFixed(hz < 100 ? 2 : 0)) + ' ops/sec ' + pm +
|
2421 | stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)';
|
2422 | }
|
2423 | return result;
|
2424 | }
|
2425 |
|
2426 |
|
2427 |
|
2428 | |
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 | function clock() {
|
2436 | var applet,
|
2437 | options = Benchmark.options,
|
2438 | template = { 'begin': 's$=new n$', 'end': 'r$=(new n$-s$)/1e3', 'uid': uid },
|
2439 | timers = [{ 'ns': timer.ns, 'res': max(0.0015, getRes('ms')), 'unit': 'ms' }];
|
2440 |
|
2441 |
|
2442 | clock = function(clone) {
|
2443 | var deferred;
|
2444 | if (clone instanceof Deferred) {
|
2445 | deferred = clone;
|
2446 | clone = deferred.benchmark;
|
2447 | }
|
2448 |
|
2449 | var bench = clone._original,
|
2450 | fn = bench.fn,
|
2451 | fnArg = deferred ? getFirstArgument(fn) || 'deferred' : '',
|
2452 | stringable = isStringable(fn);
|
2453 |
|
2454 | var source = {
|
2455 | 'setup': getSource(bench.setup, preprocess('m$.setup()')),
|
2456 | 'fn': getSource(fn, preprocess('m$.fn(' + fnArg + ')')),
|
2457 | 'fnArg': fnArg,
|
2458 | 'teardown': getSource(bench.teardown, preprocess('m$.teardown()'))
|
2459 | };
|
2460 |
|
2461 | var count = bench.count = clone.count,
|
2462 | decompilable = support.decompilation || stringable,
|
2463 | id = bench.id,
|
2464 | isEmpty = !(source.fn || stringable),
|
2465 | name = bench.name || (typeof id == 'number' ? '<Test #' + id + '>' : id),
|
2466 | ns = timer.ns,
|
2467 | result = 0;
|
2468 |
|
2469 |
|
2470 | clone.minTime = bench.minTime || (bench.minTime = bench.options.minTime = options.minTime);
|
2471 |
|
2472 |
|
2473 |
|
2474 | if (applet) {
|
2475 | try {
|
2476 | ns.nanoTime();
|
2477 | } catch(e) {
|
2478 |
|
2479 | ns = timer.ns = new applet.Packages.nano;
|
2480 | }
|
2481 | }
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 | var compiled = bench.compiled = createFunction(preprocess('t$'), interpolate(
|
2487 | preprocess(deferred
|
2488 | ? 'var d$=this,#{fnArg}=d$,m$=d$.benchmark._original,f$=m$.fn,su$=m$.setup,td$=m$.teardown;' +
|
2489 |
|
2490 | 'if(!d$.cycles){' +
|
2491 |
|
2492 | 'd$.fn=function(){var #{fnArg}=d$;if(typeof f$=="function"){try{#{fn}\n}catch(e$){f$(d$)}}else{#{fn}\n}};' +
|
2493 |
|
2494 | 'd$.teardown=function(){d$.cycles=0;if(typeof td$=="function"){try{#{teardown}\n}catch(e$){td$()}}else{#{teardown}\n}};' +
|
2495 |
|
2496 | 'if(typeof su$=="function"){try{#{setup}\n}catch(e$){su$()}}else{#{setup}\n};' +
|
2497 |
|
2498 | 't$.start(d$);' +
|
2499 |
|
2500 | '}d$.fn();return{}'
|
2501 |
|
2502 | : 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count,n$=t$.ns;#{setup}\n#{begin};' +
|
2503 | 'while(i$--){#{fn}\n}#{end};#{teardown}\nreturn{elapsed:r$,uid:"#{uid}"}'),
|
2504 | source
|
2505 | ));
|
2506 |
|
2507 | try {
|
2508 | if (isEmpty) {
|
2509 |
|
2510 |
|
2511 | throw new Error('The test "' + name + '" is empty. This may be the result of dead code removal.');
|
2512 | }
|
2513 | else if (!deferred) {
|
2514 |
|
2515 |
|
2516 | bench.count = 1;
|
2517 | compiled = (compiled.call(bench, timer) || {}).uid == uid && compiled;
|
2518 | bench.count = count;
|
2519 | }
|
2520 | } catch(e) {
|
2521 | compiled = null;
|
2522 | clone.error = e || new Error(String(e));
|
2523 | bench.count = count;
|
2524 | }
|
2525 |
|
2526 | if (decompilable && !compiled && !deferred && !isEmpty) {
|
2527 | compiled = createFunction(preprocess('t$'), interpolate(
|
2528 | preprocess(
|
2529 | (clone.error && !stringable
|
2530 | ? 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count'
|
2531 | : 'function f$(){#{fn}\n}var r$,s$,m$=this,i$=m$.count'
|
2532 | ) +
|
2533 | ',n$=t$.ns;#{setup}\n#{begin};m$.f$=f$;while(i$--){m$.f$()}#{end};' +
|
2534 | 'delete m$.f$;#{teardown}\nreturn{elapsed:r$}'
|
2535 | ),
|
2536 | source
|
2537 | ));
|
2538 |
|
2539 | try {
|
2540 |
|
2541 | bench.count = 1;
|
2542 | compiled.call(bench, timer);
|
2543 | bench.compiled = compiled;
|
2544 | bench.count = count;
|
2545 | delete clone.error;
|
2546 | }
|
2547 | catch(e) {
|
2548 | bench.count = count;
|
2549 | if (clone.error) {
|
2550 | compiled = null;
|
2551 | } else {
|
2552 | bench.compiled = compiled;
|
2553 | clone.error = e || new Error(String(e));
|
2554 | }
|
2555 | }
|
2556 | }
|
2557 |
|
2558 |
|
2559 | clone.compiled = compiled;
|
2560 |
|
2561 | if (!clone.error) {
|
2562 | result = compiled.call(deferred || bench, timer).elapsed;
|
2563 | }
|
2564 | return result;
|
2565 | };
|
2566 |
|
2567 |
|
2568 |
|
2569 | |
2570 |
|
2571 |
|
2572 | function getRes(unit) {
|
2573 | var measured,
|
2574 | begin,
|
2575 | count = 30,
|
2576 | divisor = 1e3,
|
2577 | ns = timer.ns,
|
2578 | sample = [];
|
2579 |
|
2580 |
|
2581 | while (count--) {
|
2582 | if (unit == 'us') {
|
2583 | divisor = 1e6;
|
2584 | if (ns.stop) {
|
2585 | ns.start();
|
2586 | while (!(measured = ns.microseconds())) { }
|
2587 | } else if (ns[perfName]) {
|
2588 | divisor = 1e3;
|
2589 | measured = Function('n', 'var r,s=n.' + perfName + '();while(!(r=n.' + perfName + '()-s)){};return r')(ns);
|
2590 | } else {
|
2591 | begin = ns();
|
2592 | while (!(measured = ns() - begin)) { }
|
2593 | }
|
2594 | }
|
2595 | else if (unit == 'ns') {
|
2596 | divisor = 1e9;
|
2597 | if (ns.nanoTime) {
|
2598 | begin = ns.nanoTime();
|
2599 | while (!(measured = ns.nanoTime() - begin)) { }
|
2600 | } else {
|
2601 | begin = (begin = ns())[0] + (begin[1] / divisor);
|
2602 | while (!(measured = ((measured = ns())[0] + (measured[1] / divisor)) - begin)) { }
|
2603 | divisor = 1;
|
2604 | }
|
2605 | }
|
2606 | else {
|
2607 | begin = new ns;
|
2608 | while (!(measured = new ns - begin)) { }
|
2609 | }
|
2610 |
|
2611 |
|
2612 | if (measured > 0) {
|
2613 | sample.push(measured);
|
2614 | } else {
|
2615 | sample.push(Infinity);
|
2616 | break;
|
2617 | }
|
2618 | }
|
2619 |
|
2620 | return getMean(sample) / divisor;
|
2621 | }
|
2622 |
|
2623 | |
2624 |
|
2625 |
|
2626 |
|
2627 | function preprocess(code) {
|
2628 | return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid));
|
2629 | }
|
2630 |
|
2631 |
|
2632 |
|
2633 |
|
2634 | each(doc && doc.applets || [], function(element) {
|
2635 | return !(timer.ns = applet = 'nanoTime' in element && element);
|
2636 | });
|
2637 |
|
2638 |
|
2639 | try {
|
2640 | if (typeof timer.ns.nanoTime() == 'number') {
|
2641 | timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
|
2642 | }
|
2643 | } catch(e) { }
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 | try {
|
2649 | if ((timer.ns = new (window.chrome || window.chromium).Interval)) {
|
2650 | timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
2651 | }
|
2652 | } catch(e) { }
|
2653 |
|
2654 |
|
2655 | if ((timer.ns = perfName && perfObject)) {
|
2656 | timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
2657 | }
|
2658 |
|
2659 |
|
2660 | if (processObject && typeof (timer.ns = processObject.hrtime) == 'function') {
|
2661 | timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
|
2662 | }
|
2663 |
|
2664 |
|
2665 | if (microtimeObject && typeof (timer.ns = microtimeObject.now) == 'function') {
|
2666 | timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
2667 | }
|
2668 |
|
2669 |
|
2670 | timer = reduce(timers, function(timer, other) {
|
2671 | return other.res < timer.res ? other : timer;
|
2672 | });
|
2673 |
|
2674 |
|
2675 | if (timer.unit != 'ns' && applet) {
|
2676 | applet = destroyElement(applet);
|
2677 | }
|
2678 |
|
2679 | if (timer.res == Infinity) {
|
2680 | throw new Error('Benchmark.js was unable to find a working timer.');
|
2681 | }
|
2682 |
|
2683 | if (timer.unit == 'ns') {
|
2684 | if (timer.ns.nanoTime) {
|
2685 | extend(template, {
|
2686 | 'begin': 's$=n$.nanoTime()',
|
2687 | 'end': 'r$=(n$.nanoTime()-s$)/1e9'
|
2688 | });
|
2689 | } else {
|
2690 | extend(template, {
|
2691 | 'begin': 's$=n$()',
|
2692 | 'end': 'r$=n$(s$);r$=r$[0]+(r$[1]/1e9)'
|
2693 | });
|
2694 | }
|
2695 | }
|
2696 | else if (timer.unit == 'us') {
|
2697 | if (timer.ns.stop) {
|
2698 | extend(template, {
|
2699 | 'begin': 's$=n$.start()',
|
2700 | 'end': 'r$=n$.microseconds()/1e6'
|
2701 | });
|
2702 | } else if (perfName) {
|
2703 | extend(template, {
|
2704 | 'begin': 's$=n$.' + perfName + '()',
|
2705 | 'end': 'r$=(n$.' + perfName + '()-s$)/1e3'
|
2706 | });
|
2707 | } else {
|
2708 | extend(template, {
|
2709 | 'begin': 's$=n$()',
|
2710 | 'end': 'r$=(n$()-s$)/1e6'
|
2711 | });
|
2712 | }
|
2713 | }
|
2714 |
|
2715 |
|
2716 | timer.start = createFunction(preprocess('o$'),
|
2717 | preprocess('var n$=this.ns,#{begin};o$.elapsed=0;o$.timeStamp=s$'));
|
2718 |
|
2719 | timer.stop = createFunction(preprocess('o$'),
|
2720 | preprocess('var n$=this.ns,s$=o$.timeStamp,#{end};o$.elapsed=r$'));
|
2721 |
|
2722 |
|
2723 |
|
2724 | options.minTime || (options.minTime = max(timer.res / 2 / 0.01, 0.05));
|
2725 | return clock.apply(null, arguments);
|
2726 | }
|
2727 |
|
2728 |
|
2729 |
|
2730 | |
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 | function compute(bench, options) {
|
2738 | options || (options = {});
|
2739 |
|
2740 | var async = options.async,
|
2741 | elapsed = 0,
|
2742 | initCount = bench.initCount,
|
2743 | minSamples = bench.minSamples,
|
2744 | queue = [],
|
2745 | sample = bench.stats.sample;
|
2746 |
|
2747 | |
2748 |
|
2749 |
|
2750 | function enqueue() {
|
2751 | queue.push(bench.clone({
|
2752 | '_original': bench,
|
2753 | 'events': {
|
2754 | 'abort': [update],
|
2755 | 'cycle': [update],
|
2756 | 'error': [update],
|
2757 | 'start': [update]
|
2758 | }
|
2759 | }));
|
2760 | }
|
2761 |
|
2762 | |
2763 |
|
2764 |
|
2765 | function update(event) {
|
2766 | var clone = this,
|
2767 | type = event.type;
|
2768 |
|
2769 | if (bench.running) {
|
2770 | if (type == 'start') {
|
2771 |
|
2772 | clone.count = bench.initCount;
|
2773 | }
|
2774 | else {
|
2775 | if (type == 'error') {
|
2776 | bench.error = clone.error;
|
2777 | }
|
2778 | if (type == 'abort') {
|
2779 | bench.abort();
|
2780 | bench.emit('cycle');
|
2781 | } else {
|
2782 | event.currentTarget = event.target = bench;
|
2783 | bench.emit(event);
|
2784 | }
|
2785 | }
|
2786 | } else if (bench.aborted) {
|
2787 |
|
2788 | clone.events.abort.length = 0;
|
2789 | clone.abort();
|
2790 | }
|
2791 | }
|
2792 |
|
2793 | |
2794 |
|
2795 |
|
2796 | function evaluate(event) {
|
2797 | var critical,
|
2798 | df,
|
2799 | mean,
|
2800 | moe,
|
2801 | rme,
|
2802 | sd,
|
2803 | sem,
|
2804 | variance,
|
2805 | clone = event.target,
|
2806 | done = bench.aborted,
|
2807 | now = +new Date,
|
2808 | size = sample.push(clone.times.period),
|
2809 | maxedOut = size >= minSamples && (elapsed += now - clone.times.timeStamp) / 1e3 > bench.maxTime,
|
2810 | times = bench.times,
|
2811 | varOf = function(sum, x) { return sum + pow(x - mean, 2); };
|
2812 |
|
2813 |
|
2814 | if (done || clone.hz == Infinity) {
|
2815 | maxedOut = !(size = sample.length = queue.length = 0);
|
2816 | }
|
2817 |
|
2818 | if (!done) {
|
2819 |
|
2820 | mean = getMean(sample);
|
2821 |
|
2822 | variance = reduce(sample, varOf, 0) / (size - 1) || 0;
|
2823 |
|
2824 | sd = sqrt(variance);
|
2825 |
|
2826 | sem = sd / sqrt(size);
|
2827 |
|
2828 | df = size - 1;
|
2829 |
|
2830 | critical = tTable[Math.round(df) || 1] || tTable.infinity;
|
2831 |
|
2832 | moe = sem * critical;
|
2833 |
|
2834 | rme = (moe / mean) * 100 || 0;
|
2835 |
|
2836 | extend(bench.stats, {
|
2837 | 'deviation': sd,
|
2838 | 'mean': mean,
|
2839 | 'moe': moe,
|
2840 | 'rme': rme,
|
2841 | 'sem': sem,
|
2842 | 'variance': variance
|
2843 | });
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 | if (maxedOut) {
|
2851 |
|
2852 | bench.initCount = initCount;
|
2853 | bench.running = false;
|
2854 | done = true;
|
2855 | times.elapsed = (now - times.timeStamp) / 1e3;
|
2856 | }
|
2857 | if (bench.hz != Infinity) {
|
2858 | bench.hz = 1 / mean;
|
2859 | times.cycle = mean * bench.count;
|
2860 | times.period = mean;
|
2861 | }
|
2862 | }
|
2863 |
|
2864 | if (queue.length < 2 && !maxedOut) {
|
2865 | enqueue();
|
2866 | }
|
2867 |
|
2868 | event.aborted = done;
|
2869 | }
|
2870 |
|
2871 |
|
2872 | enqueue();
|
2873 | invoke(queue, {
|
2874 | 'name': 'run',
|
2875 | 'args': { 'async': async },
|
2876 | 'queued': true,
|
2877 | 'onCycle': evaluate,
|
2878 | 'onComplete': function() { bench.emit('complete'); }
|
2879 | });
|
2880 | }
|
2881 |
|
2882 |
|
2883 |
|
2884 | |
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 | function cycle(clone, options) {
|
2892 | options || (options = {});
|
2893 |
|
2894 | var deferred;
|
2895 | if (clone instanceof Deferred) {
|
2896 | deferred = clone;
|
2897 | clone = clone.benchmark;
|
2898 | }
|
2899 |
|
2900 | var clocked,
|
2901 | cycles,
|
2902 | divisor,
|
2903 | event,
|
2904 | minTime,
|
2905 | period,
|
2906 | async = options.async,
|
2907 | bench = clone._original,
|
2908 | count = clone.count,
|
2909 | times = clone.times;
|
2910 |
|
2911 |
|
2912 | if (clone.running) {
|
2913 |
|
2914 | cycles = ++clone.cycles;
|
2915 | clocked = deferred ? deferred.elapsed : clock(clone);
|
2916 | minTime = clone.minTime;
|
2917 |
|
2918 | if (cycles > bench.cycles) {
|
2919 | bench.cycles = cycles;
|
2920 | }
|
2921 | if (clone.error) {
|
2922 | event = Event('error');
|
2923 | event.message = clone.error;
|
2924 | clone.emit(event);
|
2925 | if (!event.cancelled) {
|
2926 | clone.abort();
|
2927 | }
|
2928 | }
|
2929 | }
|
2930 |
|
2931 |
|
2932 | if (clone.running) {
|
2933 |
|
2934 | bench.times.cycle = times.cycle = clocked;
|
2935 |
|
2936 | period = bench.times.period = times.period = clocked / count;
|
2937 |
|
2938 | bench.hz = clone.hz = 1 / period;
|
2939 |
|
2940 | bench.initCount = clone.initCount = count;
|
2941 |
|
2942 | clone.running = clocked < minTime;
|
2943 |
|
2944 | if (clone.running) {
|
2945 |
|
2946 |
|
2947 | if (!clocked && (divisor = divisors[clone.cycles]) != null) {
|
2948 | count = floor(4e6 / divisor);
|
2949 | }
|
2950 |
|
2951 | if (count <= clone.count) {
|
2952 | count += Math.ceil((minTime - clocked) / period);
|
2953 | }
|
2954 | clone.running = count != Infinity;
|
2955 | }
|
2956 | }
|
2957 |
|
2958 | event = Event('cycle');
|
2959 | clone.emit(event);
|
2960 | if (event.aborted) {
|
2961 | clone.abort();
|
2962 | }
|
2963 |
|
2964 | if (clone.running) {
|
2965 |
|
2966 | clone.count = count;
|
2967 | if (deferred) {
|
2968 | clone.compiled.call(deferred, timer);
|
2969 | } else if (async) {
|
2970 | delay(clone, function() { cycle(clone, options); });
|
2971 | } else {
|
2972 | cycle(clone);
|
2973 | }
|
2974 | }
|
2975 | else {
|
2976 |
|
2977 |
|
2978 | if (support.browser) {
|
2979 | runScript(uid + '=1;delete ' + uid);
|
2980 | }
|
2981 |
|
2982 | clone.emit('complete');
|
2983 | }
|
2984 | }
|
2985 |
|
2986 |
|
2987 |
|
2988 | |
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 |
|
2997 |
|
2998 |
|
2999 |
|
3000 |
|
3001 |
|
3002 | function run(options) {
|
3003 | var me = this,
|
3004 | event = Event('start');
|
3005 |
|
3006 |
|
3007 | me.running = false;
|
3008 | me.reset();
|
3009 | me.running = true;
|
3010 |
|
3011 | me.count = me.initCount;
|
3012 | me.times.timeStamp = +new Date;
|
3013 | me.emit(event);
|
3014 |
|
3015 | if (!event.cancelled) {
|
3016 | options = { 'async': ((options = options && options.async) == null ? me.async : options) && support.timeout };
|
3017 |
|
3018 |
|
3019 | if (me._original) {
|
3020 | if (me.defer) {
|
3021 | Deferred(me);
|
3022 | } else {
|
3023 | cycle(me, options);
|
3024 | }
|
3025 | }
|
3026 |
|
3027 | else {
|
3028 | compute(me, options);
|
3029 | }
|
3030 | }
|
3031 | return me;
|
3032 | }
|
3033 |
|
3034 |
|
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 | extend(Benchmark, {
|
3043 |
|
3044 | |
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 | 'options': {
|
3052 |
|
3053 | |
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 | 'async': false,
|
3061 |
|
3062 | |
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 | 'defer': false,
|
3069 |
|
3070 | |
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 | 'delay': 0.005,
|
3076 |
|
3077 | |
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 | 'id': undefined,
|
3085 |
|
3086 | |
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 | 'initCount': 1,
|
3093 |
|
3094 | |
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 | 'maxTime': 5,
|
3102 |
|
3103 | |
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 |
|
3109 | 'minSamples': 5,
|
3110 |
|
3111 | |
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 | 'minTime': 0,
|
3118 |
|
3119 | |
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 | 'name': undefined,
|
3126 |
|
3127 | |
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 | 'onAbort': undefined,
|
3134 |
|
3135 | |
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 | 'onComplete': undefined,
|
3142 |
|
3143 | |
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 | 'onCycle': undefined,
|
3150 |
|
3151 | |
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 | 'onError': undefined,
|
3158 |
|
3159 | |
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 | 'onReset': undefined,
|
3166 |
|
3167 | |
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 | 'onStart': undefined
|
3174 | },
|
3175 |
|
3176 | |
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 | 'platform': req('platform') || window.platform || {
|
3185 |
|
3186 | |
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 |
|
3192 | 'description': window.navigator && navigator.userAgent || null,
|
3193 |
|
3194 | |
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 | 'layout': null,
|
3201 |
|
3202 | |
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 | 'product': null,
|
3209 |
|
3210 | |
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 | 'name': null,
|
3217 |
|
3218 | |
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 | 'manufacturer': null,
|
3225 |
|
3226 | |
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 | 'os': null,
|
3233 |
|
3234 | |
3235 |
|
3236 |
|
3237 |
|
3238 |
|
3239 |
|
3240 | 'prerelease': null,
|
3241 |
|
3242 | |
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 | 'version': null,
|
3249 |
|
3250 | |
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 | 'toString': function() {
|
3258 | return this.description || '';
|
3259 | }
|
3260 | },
|
3261 |
|
3262 | |
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 | 'version': '1.0.0',
|
3270 |
|
3271 |
|
3272 | 'support': support,
|
3273 |
|
3274 |
|
3275 | 'deepClone': deepClone,
|
3276 |
|
3277 |
|
3278 | 'each': each,
|
3279 |
|
3280 |
|
3281 | 'extend': extend,
|
3282 |
|
3283 |
|
3284 | 'filter': filter,
|
3285 |
|
3286 |
|
3287 | 'forEach': forEach,
|
3288 |
|
3289 |
|
3290 | 'forOwn': forOwn,
|
3291 |
|
3292 |
|
3293 | 'formatNumber': formatNumber,
|
3294 |
|
3295 |
|
3296 |
|
3297 | 'hasKey': (hasKey(Benchmark, ''), hasKey),
|
3298 |
|
3299 |
|
3300 | 'indexOf': indexOf,
|
3301 |
|
3302 |
|
3303 | 'interpolate': interpolate,
|
3304 |
|
3305 |
|
3306 | 'invoke': invoke,
|
3307 |
|
3308 |
|
3309 | 'join': join,
|
3310 |
|
3311 |
|
3312 | 'map': map,
|
3313 |
|
3314 |
|
3315 | 'pluck': pluck,
|
3316 |
|
3317 |
|
3318 | 'reduce': reduce
|
3319 | });
|
3320 |
|
3321 |
|
3322 |
|
3323 | extend(Benchmark.prototype, {
|
3324 |
|
3325 | |
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 |
|
3331 | 'count': 0,
|
3332 |
|
3333 | |
3334 |
|
3335 |
|
3336 |
|
3337 |
|
3338 |
|
3339 | 'cycles': 0,
|
3340 |
|
3341 | |
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 |
|
3347 | 'hz': 0,
|
3348 |
|
3349 | |
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 | 'compiled': undefined,
|
3356 |
|
3357 | |
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 | 'error': undefined,
|
3364 |
|
3365 | |
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 | 'fn': undefined,
|
3372 |
|
3373 | |
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 | 'aborted': false,
|
3380 |
|
3381 | |
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 | 'running': false,
|
3388 |
|
3389 | |
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 | 'setup': noop,
|
3451 |
|
3452 | |
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 | 'teardown': noop,
|
3459 |
|
3460 | |
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 | 'stats': {
|
3467 |
|
3468 | |
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 | 'moe': 0,
|
3475 |
|
3476 | |
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 | 'rme': 0,
|
3483 |
|
3484 | |
3485 |
|
3486 |
|
3487 |
|
3488 |
|
3489 |
|
3490 | 'sem': 0,
|
3491 |
|
3492 | |
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 | 'deviation': 0,
|
3499 |
|
3500 | |
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 | 'mean': 0,
|
3507 |
|
3508 | |
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 |
|
3514 | 'sample': [],
|
3515 |
|
3516 | |
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 | 'variance': 0
|
3523 | },
|
3524 |
|
3525 | |
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 | 'times': {
|
3532 |
|
3533 | |
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 |
|
3539 | 'cycle': 0,
|
3540 |
|
3541 | |
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 | 'elapsed': 0,
|
3548 |
|
3549 | |
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 | 'period': 0,
|
3556 |
|
3557 | |
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 | 'timeStamp': 0
|
3564 | },
|
3565 |
|
3566 |
|
3567 | 'abort': abort,
|
3568 |
|
3569 |
|
3570 | 'clone': clone,
|
3571 |
|
3572 |
|
3573 | 'compare': compare,
|
3574 |
|
3575 |
|
3576 | 'emit': emit,
|
3577 |
|
3578 |
|
3579 | 'listeners': listeners,
|
3580 |
|
3581 |
|
3582 | 'off': off,
|
3583 |
|
3584 |
|
3585 | 'on': on,
|
3586 |
|
3587 |
|
3588 | 'reset': reset,
|
3589 |
|
3590 |
|
3591 | 'run': run,
|
3592 |
|
3593 |
|
3594 | 'toString': toStringBench
|
3595 | });
|
3596 |
|
3597 |
|
3598 |
|
3599 | extend(Deferred.prototype, {
|
3600 |
|
3601 | |
3602 |
|
3603 |
|
3604 |
|
3605 |
|
3606 |
|
3607 | 'benchmark': null,
|
3608 |
|
3609 | |
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 | 'cycles': 0,
|
3616 |
|
3617 | |
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 | 'elapsed': 0,
|
3624 |
|
3625 | |
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 | 'timeStamp': 0,
|
3632 |
|
3633 |
|
3634 | 'resolve': resolve
|
3635 | });
|
3636 |
|
3637 |
|
3638 |
|
3639 | extend(Event.prototype, {
|
3640 |
|
3641 | |
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 | 'aborted': false,
|
3648 |
|
3649 | |
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 | 'cancelled': false,
|
3656 |
|
3657 | |
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 | 'currentTarget': undefined,
|
3664 |
|
3665 | |
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 | 'result': undefined,
|
3672 |
|
3673 | |
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 | 'target': undefined,
|
3680 |
|
3681 | |
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 | 'timeStamp': 0,
|
3688 |
|
3689 | |
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 | 'type': ''
|
3696 | });
|
3697 |
|
3698 |
|
3699 |
|
3700 | |
3701 |
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 | Suite.options = {
|
3708 |
|
3709 | |
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 | 'name': undefined
|
3716 | };
|
3717 |
|
3718 |
|
3719 |
|
3720 | extend(Suite.prototype, {
|
3721 |
|
3722 | |
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 | 'length': 0,
|
3729 |
|
3730 | |
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 | 'aborted': false,
|
3737 |
|
3738 | |
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 | 'running': false,
|
3745 |
|
3746 | |
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 | 'forEach': methodize(forEach),
|
3755 |
|
3756 | |
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 |
|
3763 | 'indexOf': methodize(indexOf),
|
3764 |
|
3765 | |
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 | 'invoke': methodize(invoke),
|
3774 |
|
3775 | |
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 | 'join': [].join,
|
3783 |
|
3784 | |
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 | 'map': methodize(map),
|
3792 |
|
3793 | |
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 | 'pluck': methodize(pluck),
|
3801 |
|
3802 | |
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 | 'pop': [].pop,
|
3809 |
|
3810 | |
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | 'push': [].push,
|
3817 |
|
3818 | |
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 | 'sort': [].sort,
|
3826 |
|
3827 | |
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 | 'reduce': methodize(reduce),
|
3836 |
|
3837 |
|
3838 | 'abort': abortSuite,
|
3839 |
|
3840 |
|
3841 | 'add': add,
|
3842 |
|
3843 |
|
3844 | 'clone': cloneSuite,
|
3845 |
|
3846 |
|
3847 | 'emit': emit,
|
3848 |
|
3849 |
|
3850 | 'filter': filterSuite,
|
3851 |
|
3852 |
|
3853 | 'listeners': listeners,
|
3854 |
|
3855 |
|
3856 | 'off': off,
|
3857 |
|
3858 |
|
3859 | 'on': on,
|
3860 |
|
3861 |
|
3862 | 'reset': resetSuite,
|
3863 |
|
3864 |
|
3865 | 'run': runSuite,
|
3866 |
|
3867 |
|
3868 | 'concat': concat,
|
3869 |
|
3870 | 'reverse': reverse,
|
3871 |
|
3872 | 'shift': shift,
|
3873 |
|
3874 | 'slice': slice,
|
3875 |
|
3876 | 'splice': splice,
|
3877 |
|
3878 | 'unshift': unshift
|
3879 | });
|
3880 |
|
3881 |
|
3882 |
|
3883 |
|
3884 | extend(Benchmark, {
|
3885 | 'Deferred': Deferred,
|
3886 | 'Event': Event,
|
3887 | 'Suite': Suite
|
3888 | });
|
3889 |
|
3890 |
|
3891 |
|
3892 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
3893 |
|
3894 | define(function() {
|
3895 | return Benchmark;
|
3896 | });
|
3897 | }
|
3898 |
|
3899 | else if (freeExports) {
|
3900 |
|
3901 | if (typeof module == 'object' && module && module.exports == freeExports) {
|
3902 | (module.exports = Benchmark).Benchmark = Benchmark;
|
3903 | }
|
3904 |
|
3905 | else {
|
3906 | freeExports.Benchmark = Benchmark;
|
3907 | }
|
3908 | }
|
3909 |
|
3910 | else {
|
3911 |
|
3912 |
|
3913 | window['Benchmark'] = Benchmark;
|
3914 | }
|
3915 |
|
3916 |
|
3917 | if (support.air) {
|
3918 | clock({ '_original': { 'fn': noop, 'count': 1, 'options': {} } });
|
3919 | }
|
3920 | }(this));
|
3921 |
|
3922 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3923 | },{"_process":5}],2:[function(require,module,exports){
|
3924 |
|
3925 | (function (root, factory) {
|
3926 | if (typeof define === 'function' && define.amd) {
|
3927 | define([], factory);
|
3928 | } else if (typeof exports === 'object') {
|
3929 | module.exports = factory();
|
3930 | } else {
|
3931 | root.snabbdom = factory();
|
3932 | }
|
3933 | }(this, function () {
|
3934 |
|
3935 | 'use strict';
|
3936 |
|
3937 | var isArr = Array.isArray;
|
3938 |
|
3939 | function isString(s) { return typeof s === 'string'; }
|
3940 | function isPrimitive(s) { return typeof s === 'string' || typeof s === 'number'; }
|
3941 | function isUndef(s) { return s === undefined; }
|
3942 |
|
3943 | function VNode(tag, props, children, text, elm) {
|
3944 | return {tag: tag, props: props, children: children, text: text, elm: elm};
|
3945 | }
|
3946 |
|
3947 | function emptyNodeAt(elm) {
|
3948 | return VNode(elm.tagName, {style: {}, class: {}}, [], undefined, elm);
|
3949 | }
|
3950 | var frag = document.createDocumentFragment();
|
3951 | var emptyNode = VNode(undefined, {style: {}, class: {}}, [], undefined);
|
3952 |
|
3953 | function h(selector, b, c) {
|
3954 | var props = {}, children, tag, i;
|
3955 | if (arguments.length === 3) {
|
3956 | props = b; children = isPrimitive(c) ? [c] : c;
|
3957 | } else if (arguments.length === 2) {
|
3958 | if (isArr(b)) { children = b; }
|
3959 | else if (isPrimitive(b)) { children = [b]; }
|
3960 | else { props = b; }
|
3961 | }
|
3962 |
|
3963 | var hashIdx = selector.indexOf('#');
|
3964 | var dotIdx = selector.indexOf('.', hashIdx);
|
3965 | var hash = hashIdx > 0 ? hashIdx : selector.length;
|
3966 | var dot = dotIdx > 0 ? dotIdx : selector.length;
|
3967 | tag = selector.slice(0, Math.min(hash, dot));
|
3968 | if (hash < dot) props.id = selector.slice(hash + 1, dot);
|
3969 | if (dotIdx > 0) props.className = selector.slice(dot+1).replace(/\./g, ' ');
|
3970 |
|
3971 | if (isArr(children)) {
|
3972 | for (i = 0; i < children.length; ++i) {
|
3973 | if (isPrimitive(children[i])) children[i] = VNode(undefined, undefined, undefined, children[i]);
|
3974 | }
|
3975 | }
|
3976 | return VNode(tag, props, children, undefined, undefined);
|
3977 | }
|
3978 |
|
3979 | function setStyles(elm, styles) {
|
3980 | for (var key in styles) {
|
3981 | elm.style[key] = styles[key];
|
3982 | }
|
3983 | }
|
3984 |
|
3985 | function updateProps(elm, oldProps, props) {
|
3986 | var key, val, name, on;
|
3987 | for (key in props) {
|
3988 | val = props[key];
|
3989 | if (key === 'style') {
|
3990 | for (name in val) {
|
3991 | on = val[name];
|
3992 | if (on !== oldProps.style[name]) {
|
3993 | elm.style[name] = val[name];
|
3994 | }
|
3995 | }
|
3996 | } else if (key === 'class') {
|
3997 | for (name in val) {
|
3998 | on = val[name];
|
3999 | if (on !== oldProps.class[name]) {
|
4000 | elm.classList[on ? 'add' : 'remove'](name);
|
4001 | }
|
4002 | }
|
4003 | } else {
|
4004 | elm[key] = val;
|
4005 | }
|
4006 | }
|
4007 | }
|
4008 |
|
4009 | function createElm(vnode) {
|
4010 | var elm;
|
4011 | if (isUndef(vnode.text)) {
|
4012 | elm = document.createElement(vnode.tag);
|
4013 | updateProps(elm, emptyNode.props, vnode.props);
|
4014 | var children = vnode.children;
|
4015 | if (isArr(children)) {
|
4016 | for (var i = 0; i < vnode.children.length; ++i) {
|
4017 | elm.appendChild(createElm(children[i]));
|
4018 | }
|
4019 | }
|
4020 | } else {
|
4021 | elm = document.createTextNode(vnode.text);
|
4022 | }
|
4023 | vnode.elm = elm;
|
4024 | return elm;
|
4025 | }
|
4026 |
|
4027 | function getKey(vnode) {
|
4028 | return isUndef(vnode.props) ? undefined : vnode.props.key;
|
4029 | }
|
4030 |
|
4031 | function sameVnode(vnode1, vnode2) {
|
4032 | return isUndef(vnode1.key) ? vnode1.tag === vnode2.tag
|
4033 | : getKey(vnode1) === getKey(vnode2);
|
4034 | }
|
4035 |
|
4036 | function createKeyToOldIdx(children, beginIdx, endIdx) {
|
4037 | var i, map = {};
|
4038 | for (i = beginIdx; i <= endIdx; ++i) {
|
4039 | var ch = children[i];
|
4040 | if (!isUndef(ch.props) && !isUndef(ch.props.key)) {
|
4041 | map[ch.props.key] = i;
|
4042 | }
|
4043 | }
|
4044 | return map;
|
4045 | }
|
4046 |
|
4047 | function updateChildren(parentElm, oldCh, newCh) {
|
4048 | if (isUndef(oldCh) && isUndef(newCh)) {
|
4049 | return;
|
4050 | }
|
4051 | var oldStartIdx = 0, oldEndIdx = oldCh.length - 1;
|
4052 | var newStartIdx = 0, newEndIdx = newCh.length - 1;
|
4053 | var oldStartVnode = oldCh[0], oldEndVnode = oldCh[oldEndIdx];
|
4054 | var newStartVnode = newCh[0], newEndVnode = newCh[newEndIdx];
|
4055 |
|
4056 | var oldKeyToIdx;
|
4057 |
|
4058 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
4059 | if (isUndef(oldStartVnode)) {
|
4060 | oldStartVnode = oldCh[++oldStartIdx];
|
4061 | } else if (isUndef(oldEndVnode)) {
|
4062 | oldEndVnode = oldCh[--oldEndIdx];
|
4063 | } else if (sameVnode(oldStartVnode, newStartVnode)) {
|
4064 | patchElm(oldStartVnode, newStartVnode);
|
4065 | oldStartVnode = oldCh[++oldStartIdx];
|
4066 | newStartVnode = newCh[++newStartIdx];
|
4067 | } else if (sameVnode(oldEndVnode, newEndVnode)) {
|
4068 | patchElm(oldEndVnode, newEndVnode);
|
4069 | oldEndVnode = oldCh[--oldEndIdx];
|
4070 | newEndVnode = newCh[--newEndIdx];
|
4071 | } else if (!isUndef(oldStartVnode) && !isUndef(newEndVnode) &&
|
4072 | sameVnode(oldStartVnode, newEndVnode)) {
|
4073 | patchElm(oldStartVnode, newEndVnode);
|
4074 | parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);
|
4075 | oldStartVnode = oldCh[++oldStartIdx];
|
4076 | newEndVnode = newCh[--newEndIdx];
|
4077 | } else if (!isUndef(oldEndVnode) && !isUndef(newStartVnode) &&
|
4078 | sameVnode(oldEndVnode, newStartVnode)) {
|
4079 | patchElm(oldEndVnode, newStartVnode);
|
4080 | parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);
|
4081 | oldEndVnode = oldCh[--oldEndIdx];
|
4082 | newStartVnode = newCh[++newStartIdx];
|
4083 | } else {
|
4084 | if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
4085 | var idxInOld = oldKeyToIdx[getKey(newStartVnode)];
|
4086 | if (isUndef(idxInOld)) {
|
4087 | createElm(newStartVnode);
|
4088 | parentElm.insertBefore(newStartVnode.elm, oldStartVnode.elm);
|
4089 | newStartVnode = newCh[++newStartIdx];
|
4090 | } else {
|
4091 | var elmToMove = oldCh[idxInOld];
|
4092 | patchElm(elmToMove, newStartVnode);
|
4093 | oldCh[idxInOld] = undefined;
|
4094 | parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);
|
4095 | newStartVnode = newCh[++newStartIdx];
|
4096 | }
|
4097 | }
|
4098 | }
|
4099 | if (oldStartIdx > oldEndIdx) {
|
4100 | for (; newStartIdx <= newEndIdx; ++newStartIdx) {
|
4101 | frag.appendChild(createElm(newCh[newStartIdx]));
|
4102 | }
|
4103 | if (isUndef(oldStartVnode)) {
|
4104 | parentElm.appendChild(frag);
|
4105 | } else {
|
4106 | parentElm.insertBefore(frag, oldStartVnode.elm);
|
4107 | }
|
4108 | } else if (newStartIdx > newEndIdx) {
|
4109 | for (; oldStartIdx <= oldEndIdx; ++oldStartIdx) {
|
4110 | var ch = oldCh[oldStartIdx];
|
4111 | if (!isUndef(ch)) {
|
4112 | parentElm.removeChild(oldCh[oldStartIdx].elm);
|
4113 | oldCh[oldStartIdx].elm = undefined;
|
4114 | }
|
4115 | }
|
4116 | }
|
4117 | }
|
4118 |
|
4119 | function patchElm(oldVnode, newVnode) {
|
4120 | var elm = newVnode.elm = oldVnode.elm;
|
4121 | if (isUndef(newVnode.text)) {
|
4122 | updateProps(elm, oldVnode.props, newVnode.props);
|
4123 | updateChildren(elm, oldVnode.children, newVnode.children);
|
4124 | } else {
|
4125 | if (oldVnode.text !== newVnode.text) {
|
4126 | elm.textContent = newVnode.text;
|
4127 | }
|
4128 | }
|
4129 | return newVnode;
|
4130 | }
|
4131 |
|
4132 | return {h: h, createElm: createElm, patchElm: patchElm, patch: patchElm, emptyNodeAt: emptyNodeAt, emptyNode: emptyNode};
|
4133 |
|
4134 | }));
|
4135 |
|
4136 | },{}],3:[function(require,module,exports){
|
4137 | (function (global){
|
4138 | var Benchmark = require('benchmark');
|
4139 | var a = require('../snabbdom.js');
|
4140 | var b = require('../oldsnabbdom.js');
|
4141 |
|
4142 | global.a = a;
|
4143 | global.b = b;
|
4144 |
|
4145 | var suite = new Benchmark.Suite();
|
4146 |
|
4147 | a.spanNum = function spanNum(n) {
|
4148 | return a.h('span', {key: n}, n.toString());
|
4149 | };
|
4150 |
|
4151 | b.spanNum = function spanNum(n) {
|
4152 | return b.h('span', {key: n}, n.toString());
|
4153 | };
|
4154 |
|
4155 | var elms = global.elms = 10;
|
4156 | var arr = global.arr = [];
|
4157 | for (var n = 0; n < elms; ++n) { arr[n] = n; }
|
4158 |
|
4159 | document.addEventListener('DOMContentLoaded', function() {
|
4160 | var elm = global.elm = document.getElementById('container');
|
4161 |
|
4162 | suite.add('a/ insert first', {
|
4163 | setup: function() {
|
4164 | var vnode1 = a.h('div', arr.map(a.spanNum));
|
4165 | var vnode2 = a.h('div', ['new'].concat(arr).map(a.spanNum));
|
4166 | },
|
4167 | fn: function() {
|
4168 | var emptyNode = a.emptyNodeAt(elm);
|
4169 | a.patch(emptyNode, vnode1);
|
4170 | a.patch(vnode1, vnode2);
|
4171 | a.patch(vnode2, a.emptyNode);
|
4172 | },
|
4173 | })
|
4174 | .add('b/ insert first', {
|
4175 | setup: function() {
|
4176 | var vnode1 = b.h('div', arr.map(b.spanNum));
|
4177 | var vnode2 = b.h('div', ['new'].concat(arr).map(b.spanNum));
|
4178 | },
|
4179 | fn: function() {
|
4180 | var emptyNode = b.emptyNodeAt(elm);
|
4181 | b.patch(emptyNode, vnode1);
|
4182 | b.patch(vnode1, vnode2);
|
4183 | b.patch(vnode2, b.emptyNode);
|
4184 | },
|
4185 | })
|
4186 |
|
4187 | .on('cycle', function(event) {
|
4188 | console.log(String(event.target));
|
4189 | })
|
4190 | .on('complete', function() {
|
4191 | console.log('Fastest is ' + this.filter('fastest').pluck('name'));
|
4192 | })
|
4193 |
|
4194 | .run({async: true});
|
4195 | });
|
4196 |
|
4197 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4198 | },{"../oldsnabbdom.js":2,"../snabbdom.js":4,"benchmark":1}],4:[function(require,module,exports){
|
4199 |
|
4200 | (function (root, factory) {
|
4201 | if (typeof define === 'function' && define.amd) {
|
4202 | define([], factory);
|
4203 | } else if (typeof exports === 'object') {
|
4204 | module.exports = factory();
|
4205 | } else {
|
4206 | root.snabbdom = factory();
|
4207 | }
|
4208 | }(this, function () {
|
4209 |
|
4210 | 'use strict';
|
4211 |
|
4212 | var isArr = Array.isArray;
|
4213 |
|
4214 | function isString(s) { return typeof s === 'string'; }
|
4215 | function isPrimitive(s) { return typeof s === 'string' || typeof s === 'number'; }
|
4216 | function isUndef(s) { return s === undefined; }
|
4217 |
|
4218 | function VNode(tag, props, children, text, elm) {
|
4219 | var key = !isUndef(props) ? props.key : undefined;
|
4220 | return {tag: tag, props: props, children: children,
|
4221 | text: text, elm: elm, key: key};
|
4222 | }
|
4223 |
|
4224 | function emptyNodeAt(elm) {
|
4225 | return VNode(elm.tagName, {style: {}, class: {}}, [], undefined, elm);
|
4226 | }
|
4227 | var frag = document.createDocumentFragment();
|
4228 | var emptyNode = VNode(undefined, {style: {}, class: {}}, [], undefined);
|
4229 |
|
4230 | function h(selector, b, c) {
|
4231 | var props = {}, children, tag, text, i;
|
4232 | if (arguments.length === 3) {
|
4233 | props = b;
|
4234 | if (isArr(c)) { children = c; }
|
4235 | else if (isPrimitive(c)) { text = c; }
|
4236 | } else if (arguments.length === 2) {
|
4237 | if (isArr(b)) { children = b; }
|
4238 | else if (isPrimitive(b)) { text = b; }
|
4239 | else { props = b; }
|
4240 | }
|
4241 |
|
4242 | var hashIdx = selector.indexOf('#');
|
4243 | var dotIdx = selector.indexOf('.', hashIdx);
|
4244 | var hash = hashIdx > 0 ? hashIdx : selector.length;
|
4245 | var dot = dotIdx > 0 ? dotIdx : selector.length;
|
4246 | tag = selector.slice(0, Math.min(hash, dot));
|
4247 | if (hash < dot) props.id = selector.slice(hash + 1, dot);
|
4248 | if (dotIdx > 0) props.className = selector.slice(dot+1).replace(/\./g, ' ');
|
4249 |
|
4250 | if (isArr(children)) {
|
4251 | for (i = 0; i < children.length; ++i) {
|
4252 | if (isPrimitive(children[i])) children[i] = VNode(undefined, undefined, undefined, children[i]);
|
4253 | }
|
4254 | }
|
4255 | return VNode(tag, props, children, text, undefined);
|
4256 | }
|
4257 |
|
4258 | function updateProps(elm, oldProps, props) {
|
4259 | var key, val, name, on;
|
4260 | for (key in props) {
|
4261 | val = props[key];
|
4262 | if (key === 'style') {
|
4263 | for (name in val) {
|
4264 | on = val[name];
|
4265 | if (on !== oldProps.style[name]) {
|
4266 | elm.style[name] = val[name];
|
4267 | }
|
4268 | }
|
4269 | } else if (key === 'class') {
|
4270 | for (name in val) {
|
4271 | on = val[name];
|
4272 | if (on !== oldProps.class[name]) {
|
4273 | elm.classList[on ? 'add' : 'remove'](name);
|
4274 | }
|
4275 | }
|
4276 | } else if (key !== 'key') {
|
4277 | elm[key] = val;
|
4278 | }
|
4279 | }
|
4280 | }
|
4281 |
|
4282 | function createElm(vnode) {
|
4283 | var elm, children;
|
4284 | if (!isUndef(vnode.tag)) {
|
4285 | elm = document.createElement(vnode.tag);
|
4286 | if (!isUndef(vnode.tag)) {
|
4287 | updateProps(elm, emptyNode.props, vnode.props);
|
4288 | }
|
4289 | children = vnode.children;
|
4290 | if (isArr(children)) {
|
4291 | for (var i = 0; i < vnode.children.length; ++i) {
|
4292 | elm.appendChild(createElm(children[i]));
|
4293 | }
|
4294 | } else if (isPrimitive(vnode.text)) {
|
4295 | elm.textContent = vnode.text;
|
4296 | }
|
4297 | } else {
|
4298 | elm = document.createTextNode(vnode.text);
|
4299 | }
|
4300 | vnode.elm = elm;
|
4301 | return elm;
|
4302 | }
|
4303 |
|
4304 | function sameVnode(vnode1, vnode2) {
|
4305 | return vnode1.key === vnode2.key && vnode1.tag === vnode2.tag;
|
4306 | }
|
4307 |
|
4308 | function createKeyToOldIdx(children, beginIdx, endIdx) {
|
4309 | var i, map = {};
|
4310 | for (i = beginIdx; i <= endIdx; ++i) {
|
4311 | var ch = children[i];
|
4312 | if (!isUndef(ch.props) && !isUndef(ch.props.key)) {
|
4313 | map[ch.props.key] = i;
|
4314 | }
|
4315 | }
|
4316 | return map;
|
4317 | }
|
4318 |
|
4319 | function updateChildren(parentElm, oldCh, newCh) {
|
4320 | var oldStartIdx = 0, oldEndIdx, oldStartVnode, oldEndVnode;
|
4321 | if (isUndef(oldCh)) {
|
4322 | oldEndIdx = -1;
|
4323 | } else {
|
4324 | oldEndIdx = oldCh.length - 1;
|
4325 | oldStartVnode = oldCh[0];
|
4326 | oldEndVnode = oldCh[oldEndIdx];
|
4327 | }
|
4328 |
|
4329 | var newStartIdx = 0, newEndIdx, newStartVnode, newEndVnode;
|
4330 | if (isUndef(newCh)) {
|
4331 | newEndIdx = -1;
|
4332 | } else {
|
4333 | newEndIdx = newCh.length - 1;
|
4334 | newStartVnode = newCh[0];
|
4335 | newEndVnode = newCh[newEndIdx];
|
4336 | }
|
4337 |
|
4338 | var oldKeyToIdx;
|
4339 |
|
4340 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
4341 | if (isUndef(oldStartVnode)) {
|
4342 | oldStartVnode = oldCh[++oldStartIdx];
|
4343 | } else if (isUndef(oldEndVnode)) {
|
4344 | oldEndVnode = oldCh[--oldEndIdx];
|
4345 | } else if (sameVnode(oldStartVnode, newStartVnode)) {
|
4346 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx &&
|
4347 | !isUndef(oldStartVnode) && sameVnode(oldStartVnode, newStartVnode)) {
|
4348 | patchElm(oldStartVnode, newStartVnode);
|
4349 | oldStartVnode = oldCh[++oldStartIdx];
|
4350 | newStartVnode = newCh[++newStartIdx];
|
4351 | }
|
4352 | } else if (sameVnode(oldEndVnode, newEndVnode)) {
|
4353 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx &&
|
4354 | !isUndef(oldEndVnode) && sameVnode(oldEndVnode, newEndVnode)) {
|
4355 | patchElm(oldEndVnode, newEndVnode);
|
4356 | oldEndVnode = oldCh[--oldEndIdx];
|
4357 | newEndVnode = newCh[--newEndIdx];
|
4358 | }
|
4359 | } else if (!isUndef(oldStartVnode) && !isUndef(newEndVnode) &&
|
4360 | sameVnode(oldStartVnode, newEndVnode)) {
|
4361 | patchElm(oldStartVnode, newEndVnode);
|
4362 | parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);
|
4363 | oldStartVnode = oldCh[++oldStartIdx];
|
4364 | newEndVnode = newCh[--newEndIdx];
|
4365 | } else if (!isUndef(oldEndVnode) && !isUndef(newStartVnode) &&
|
4366 | sameVnode(oldEndVnode, newStartVnode)) {
|
4367 | patchElm(oldEndVnode, newStartVnode);
|
4368 | parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);
|
4369 | oldEndVnode = oldCh[--oldEndIdx];
|
4370 | newStartVnode = newCh[++newStartIdx];
|
4371 | } else {
|
4372 | if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
4373 | var idxInOld = oldKeyToIdx[newStartVnode.key];
|
4374 | if (isUndef(idxInOld)) {
|
4375 | createElm(newStartVnode);
|
4376 | parentElm.insertBefore(newStartVnode.elm, oldStartVnode.elm);
|
4377 | newStartVnode = newCh[++newStartIdx];
|
4378 | } else {
|
4379 | var elmToMove = oldCh[idxInOld];
|
4380 | patchElm(elmToMove, newStartVnode);
|
4381 | oldCh[idxInOld] = undefined;
|
4382 | parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);
|
4383 | newStartVnode = newCh[++newStartIdx];
|
4384 | }
|
4385 | }
|
4386 | }
|
4387 | if (oldStartIdx > oldEndIdx) {
|
4388 | for (; newStartIdx <= newEndIdx; ++newStartIdx) {
|
4389 | frag.appendChild(createElm(newCh[newStartIdx]));
|
4390 | }
|
4391 | if (isUndef(oldStartVnode)) {
|
4392 | parentElm.appendChild(frag);
|
4393 | } else {
|
4394 | parentElm.insertBefore(frag, oldStartVnode.elm);
|
4395 | }
|
4396 | } else if (newStartIdx > newEndIdx) {
|
4397 | for (; oldStartIdx <= oldEndIdx; ++oldStartIdx) {
|
4398 | var ch = oldCh[oldStartIdx];
|
4399 | if (!isUndef(ch)) {
|
4400 | parentElm.removeChild(oldCh[oldStartIdx].elm);
|
4401 | oldCh[oldStartIdx].elm = undefined;
|
4402 | }
|
4403 | }
|
4404 | }
|
4405 | }
|
4406 |
|
4407 | function patchElm(oldVnode, newVnode) {
|
4408 | var elm = newVnode.elm = oldVnode.elm;
|
4409 | if (!isUndef(newVnode.props)) {
|
4410 | updateProps(elm, oldVnode.props, newVnode.props);
|
4411 | }
|
4412 | if (isUndef(newVnode.text)) {
|
4413 | updateChildren(elm, oldVnode.children, newVnode.children);
|
4414 | } else {
|
4415 | if (oldVnode.text !== newVnode.text) elm.textContent = newVnode.text;
|
4416 | }
|
4417 | return newVnode;
|
4418 | }
|
4419 |
|
4420 | return {h: h, createElm: createElm, patchElm: patchElm, patch: patchElm, emptyNodeAt: emptyNodeAt, emptyNode: emptyNode};
|
4421 |
|
4422 | }));
|
4423 |
|
4424 | },{}],5:[function(require,module,exports){
|
4425 |
|
4426 |
|
4427 | var process = module.exports = {};
|
4428 |
|
4429 | process.nextTick = (function () {
|
4430 | var canSetImmediate = typeof window !== 'undefined'
|
4431 | && window.setImmediate;
|
4432 | var canMutationObserver = typeof window !== 'undefined'
|
4433 | && window.MutationObserver;
|
4434 | var canPost = typeof window !== 'undefined'
|
4435 | && window.postMessage && window.addEventListener
|
4436 | ;
|
4437 |
|
4438 | if (canSetImmediate) {
|
4439 | return function (f) { return window.setImmediate(f) };
|
4440 | }
|
4441 |
|
4442 | var queue = [];
|
4443 |
|
4444 | if (canMutationObserver) {
|
4445 | var hiddenDiv = document.createElement("div");
|
4446 | var observer = new MutationObserver(function () {
|
4447 | var queueList = queue.slice();
|
4448 | queue.length = 0;
|
4449 | queueList.forEach(function (fn) {
|
4450 | fn();
|
4451 | });
|
4452 | });
|
4453 |
|
4454 | observer.observe(hiddenDiv, { attributes: true });
|
4455 |
|
4456 | return function nextTick(fn) {
|
4457 | if (!queue.length) {
|
4458 | hiddenDiv.setAttribute('yes', 'no');
|
4459 | }
|
4460 | queue.push(fn);
|
4461 | };
|
4462 | }
|
4463 |
|
4464 | if (canPost) {
|
4465 | window.addEventListener('message', function (ev) {
|
4466 | var source = ev.source;
|
4467 | if ((source === window || source === null) && ev.data === 'process-tick') {
|
4468 | ev.stopPropagation();
|
4469 | if (queue.length > 0) {
|
4470 | var fn = queue.shift();
|
4471 | fn();
|
4472 | }
|
4473 | }
|
4474 | }, true);
|
4475 |
|
4476 | return function nextTick(fn) {
|
4477 | queue.push(fn);
|
4478 | window.postMessage('process-tick', '*');
|
4479 | };
|
4480 | }
|
4481 |
|
4482 | return function nextTick(fn) {
|
4483 | setTimeout(fn, 0);
|
4484 | };
|
4485 | })();
|
4486 |
|
4487 | process.title = 'browser';
|
4488 | process.browser = true;
|
4489 | process.env = {};
|
4490 | process.argv = [];
|
4491 |
|
4492 | function noop() {}
|
4493 |
|
4494 | process.on = noop;
|
4495 | process.addListener = noop;
|
4496 | process.once = noop;
|
4497 | process.off = noop;
|
4498 | process.removeListener = noop;
|
4499 | process.removeAllListeners = noop;
|
4500 | process.emit = noop;
|
4501 |
|
4502 | process.binding = function (name) {
|
4503 | throw new Error('process.binding is not supported');
|
4504 | };
|
4505 |
|
4506 |
|
4507 | process.cwd = function () { return '/' };
|
4508 | process.chdir = function (dir) {
|
4509 | throw new Error('process.chdir is not supported');
|
4510 | };
|
4511 |
|
4512 | },{}]},{},[3]);
|