Skip to content

Commit 28e2ce0

Browse files
tweak (#339)
use % 50 - this halves the arrays sizes to check against: i.e 16.67 == 66.67 - i.e we still 0's, 100s, 60FPS, etc
1 parent 907c8aa commit 28e2ce0

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

js/generic.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1401,13 +1401,12 @@ function addDetail(metric, data, scope = isScope) {
14011401

14021402
function addTiming(metric) {
14031403
let remainder = gCountTiming % 9, key, value
1404-
if (0 == gCountTiming % 3) {
1404+
if (0 == gCountTiming % 5) {
14051405
// get extra dates
14061406
try {gData.timing['date'].push((new Date())[Symbol.toPrimitive]('number'))} catch(e) {}
14071407
}
14081408
try {
14091409
if (0 == remainder) {
1410-
// exslt
14111410
key = 'exslt'
14121411
const xslText = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
14131412
+' xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date"><xsl:output method="html"/>'
@@ -1420,7 +1419,7 @@ function addTiming(metric) {
14201419
} else if (1 == remainder) {
14211420
key = 'now'; value = performance.now()
14221421
} else if (2 == remainder) {
1423-
key = 'currenttime'; value = new DocumentTimeline().currentTime
1422+
key = 'currenttime'; value = gTimeline.currentTime
14241423
} else if (3 == remainder) {
14251424
key = 'timestamp'; value = new Event('').timeStamp
14261425
} else if (4 == remainder) {
@@ -1433,7 +1432,6 @@ function addTiming(metric) {
14331432
} else if (7 == remainder) {
14341433
try {gData.timing['timestamp'].push(new Event('').timeStamp)} catch(e) {}
14351434
}
1436-
14371435
if (undefined !== key) {
14381436
if (runST) {value = undefined}
14391437
gData.timing[key].push(value)
@@ -1823,13 +1821,16 @@ function outputSection(id, isResize = false) {
18231821
// get a first value for each to ensure a max diff
18241822
try {gData.timing['now'].push(performance.now())} catch(e) {}
18251823
try {gData.timing['timestamp'].push(new Event('').timeStamp)} catch(e) {}
1826-
try {gData.timing['currenttime'].push(new DocumentTimeline().currentTime)} catch(e) {}
1824+
try {
1825+
gTimeline = new DocumentTimeline()
1826+
gData.timing['currenttime'].push(gTimeline.currentTime)
1827+
} catch(e) {}
18271828
try {
18281829
performance.clearMarks('a')
18291830
gData.timing['mark'].push(performance.mark('a').startTime)
18301831
} catch(e) {}
18311832
gCountTiming = 0
1832-
addTiming('start')
1833+
addTiming('start') // adds first exslt
18331834

18341835
// run sequentially awaiting each before running the next
18351836
// order: use number or section name

js/globals.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let gData = { // from sData
3131
'timing': {},
3232
}
3333
let gTiming = ['currenttime','date','exslt','mark','now','timestamp']
34+
let gTimeline
3435

3536
// section
3637
let sData = {}, // final sorted section data: from sDataTemp

js/misc.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function check_timing(type) {
1515
} else if ('mark' == type) {
1616
value = performance.mark('a').startTime - performance.mark('a').startTime
1717
} else if ('currenttime' == type) {
18-
value = (new DocumentTimeline().currentTime) - (new DocumentTimeline().currentTime)
18+
value = (gTimeline.currentTime) - (gTimeline.currentTime)
1919
}
2020
value = Math.trunc(value)
2121
// should match or the clock ticks over, e.g. 1ms or 16/17ms
@@ -43,38 +43,31 @@ function get_timing(METRIC) {
4343
gData.timing['mark'].push(performance.mark('a').startTime)
4444
} catch(e) {}
4545
try {gData.timing['date'].push((new Date())[Symbol.toPrimitive]('number'))} catch(e) {}
46-
try {gData.timing['currenttime'].push(new DocumentTimeline().currentTime)} catch(e) {}
46+
try {gData.timing['currenttime'].push(gTimeline.currentTime)} catch(e) {}
4747

4848
/* testing
4949
gData.timing.date = [1723240561321]
5050
gData.timing.exslt = ['2024-08-09T20:23:10.000','2024-08-09T20:23:11.000']
51+
gData.timing.currenttime = [4800.096,4833.43,4850.097,4866.764,4883.431,4900.098,4916.765,4933.432,4950.099,4966.766,4983.433]
5152
//*/
5253

5354
let oGood = {
54-
'date': [0, 1, 16, 17, 33, 34, 50, 66, 67, 83, 84],
55-
// 1912129: exslt diffs must be 1000, and all end in .000
55+
'date': [0, 1, 16, 17, 33, 34],
5656
'currenttime': [
57-
// we're 2 decimal places, no drift
58-
0,
59-
16.66, 16.67,
60-
33.33, 33.34,
61-
50,
62-
66.66, 66.67,
63-
83.33, 83.34,
57+
0, 0.01, 0.02,
58+
16.66, 16.67, 16.68,
59+
33.33, 33.34, 33.35,
6460
],
65-
'exslt': [0],
61+
'exslt': [0], // 1912129: exslt diffs must be 1000, and all end in .000
6662
'other': [
6763
// tested 20/10mn timestamps over ~12s/6s = ~750/370 unique times
6864
// the longer since the first time, the more decimal points drift
6965
// so 0's become 0.1's then 0.2's etc: 6s seems to limit drift to 1 decimal point
70-
0, 0.1, 0.2,
71-
16.6, 16.7, 16.8, //16.9,
72-
33.3, 33.4, 33.5,
73-
50, 50.1, 50.2,
74-
66.6, 66.7, 66.8, //66.9,
75-
83.3, 83.4, 83.5
66+
0, 0.1, 0.2, 0.3,
67+
16.6, 16.7, 16.8, 16.9,
68+
33.3, 33.4, 33.5, 33.36,
7669
],
77-
'ten': [0, 10, 20, 30, 40, 50, 60, 70, 80, 90],
70+
'ten': [0, 10, 20, 30, 40],
7871
}
7972

8073
let aNotInteger = ['mark','now','timestamp']
@@ -132,11 +125,12 @@ function get_timing(METRIC) {
132125
let totaldiff = (end - start)
133126
totaldiff = ('currenttime' == k ? (totaldiff.toFixed(2)) : (totaldiff.toString().match(calc1)[0]) ) * 1
134127
aTotal.push(totaldiff)
135-
let diff = (totaldiff % 100).toFixed(2) * 1 // drop hundreds
128+
let diff = (totaldiff % 50).toFixed(2) * 1 // drop 50s
136129
setDiffs.add(diff)
137130
}
138131
let aDiffs = Array.from(setDiffs)
139132
//if ('currenttime' == k) {console.log(aDiffs)}
133+
140134
// test intervals
141135
for (let i=0; i < aDiffs.length; i++) {
142136
if (isMatch && !aGood.includes(aDiffs[i])) {isMatch = false}
@@ -176,9 +170,10 @@ function get_timing(METRIC) {
176170

177171
// display
178172
str = aTotal.join(', ')
179-
if (str.length > 60) {
180-
let reduce = Math.floor((str.length - 60)/5)
181-
let len = aTotal.length
173+
let strLen = str.length
174+
if (strLen > 60) {
175+
let len = aTotal.length, unitLen = strLen/(aTotal.length)
176+
let reduce = Math.floor((str.length - 60)/unitLen)
182177
let lasttwo = ' &#x2026 '+ aTotal[len-2] +', '+aTotal[len-1]
183178
let newTotal = aTotal.slice(0, len - (reduce + 2))
184179
if ((newTotal.join(', ') + lasttwo).length > 60) {newTotal = newTotal.slice(0, len - (reduce + 3))}

0 commit comments

Comments
 (0)