UNPKG

1.6 kBJavaScriptView Raw
1var util = require('util')
2, diff = require('..')
3, data = require('./practice-data')
4;
5
6var cycle = -1
7, i
8, len = data.length
9, prior = {}
10, comparand
11, records
12, roll = []
13, ch
14, stat
15, stats = []
16, mark, elapsed, avg = { diff: { ttl: 0 }, apply: { ttl: 0 } }, ttl = 0
17;
18
19mark = process.hrtime();
20while(++cycle < 10) {
21 i = -1;
22 while(++i < len) {
23 stats.push(stat = { mark: process.hrtime() });
24
25 comparand = roll[i] || data[i];
26
27 stat.diff = { mark: process.hrtime() };
28 records = diff(prior, comparand);
29 stat.diff.intv = process.hrtime(stat.diff.mark);
30
31 if (records) {
32 stat.apply = { count: diff.length, mark: process.hrtime() };
33 records.forEach(function(ch) {
34 diff.applyChange(prior, comparand, ch);
35 });
36 stat.apply.intv = process.hrtime(stat.apply.mark);
37
38 prior = comparand;
39 }
40 stat.intv = process.hrtime(stat.mark);
41 }
42}
43
44function ms(intv) {
45 return (intv[0]*1e9 + intv[1]/1e6);
46}
47elapsed = ms(process.hrtime(mark));
48
49stats.forEach(function(stat) {
50 stat.elapsed = ms(stat.intv);
51 stat.diff.elapsed = ms(stat.diff.intv);
52 avg.diff.ttl += stat.diff.elapsed;
53 if (stat.apply) {
54 stat.apply.elapsed = ms(stat.apply.intv);
55 ttl += stat.apply.count;
56 avg.apply.ttl += stat.apply.elapsed;
57 }
58});
59
60avg.diff.avg = avg.diff.ttl / ttl;
61avg.apply.avg = avg.apply.ttl / ttl;
62
63console.log('Captured '.concat(stats.length, ' samples with ', ttl, ' combined differences in ', elapsed, 'ms'));
64console.log('\tavg diff: '.concat(avg.diff.avg, 'ms or ', (1 / avg.diff.avg), ' per ms'));
65console.log('\tavg apply: '.concat(avg.apply.avg, 'ms or ', (1 / avg.apply.avg), ' per ms'));