CXOptimizeCollector/JavaScriptCollector/Boomerang/Plugins/restiming.js
/**
	 * Calculates the union of durations of the specified resources.  If
	 * any resources overlap, those timeslices are not double-counted.
	 *
	 * @param [ResourceTiming[]] resources Resources
	 *
	 * @returns Duration, in milliseconds
	 */
Calculates the union of durations of the specified resources.  If
any resources overlap, those timeslices are not double-counted.

@param [ResourceTiming[]] resources Resources

@returns Duration, in milliseconds
Calculates the union of durations of the specified resources . If any resources overlap those timeslices are not double - counted . @param [ ResourceTiming [] ] resources Resources @returns Duration in milliseconds
function calculateResourceTimingUnion(resources) {
		var i;
		if (!resources || !resources.length) {
			return 0;
		}
		resources.sort(function(a, b) {
			if (a.fetchStart !== b.fetchStart) {
				return a.fetchStart - b.fetchStart;
			}
			else {
				var ae = a.responseStart || a.responseEnd;
				var be = b.responseStart || b.responseEnd;
				return ae - be;
			}
		});
		var times = reduceFetchStarts(resources);
		var times2 = [];
		var furthestEnd = 0;
		for (i = 0; i < times.length; i++) {
			var res = times[i];
			if (res.fetchStart < furthestEnd) {
				res.fetchStart = furthestEnd;
			}
			if (res.fetchStart < res.responseEnd) {
				times2.push(res);
				furthestEnd = res.responseEnd;
			}
		}
		var times3 = reduceFetchStarts(times2);
		var totalTime = 0;
		for (i = 0; i < times3.length; i++) {
			totalTime += times3[i].responseEnd - times3[i].fetchStart;
		}
		return totalTime;
	}
function calculateResourceTimingUnion ( resources ) { var i ; if ( ! resources || ! resources . length ) { return 0 ; } resources . sort ( function ( a , b ) { if ( a . fetchStart !== b . fetchStart ) { return a . fetchStart - b . fetchStart ; } else { var ae = a . responseStart || a . responseEnd ; var be = b . responseStart || b . responseEnd ; return ae - be ; } } ) ; var times = reduceFetchStarts ( resources ) ; var times2 = [ ] ; var furthestEnd = 0 ; for ( i = 0 ; i < times . length ; i ++ ) { var res = times [ i ] ; if ( res . fetchStart < furthestEnd ) { res . fetchStart = furthestEnd ; } if ( res . fetchStart < res . responseEnd ) { times2 . push ( res ) ; furthestEnd = res . responseEnd ; } } var times3 = reduceFetchStarts ( times2 ) ; var totalTime = 0 ; for ( i = 0 ; i < times3 . length ; i ++ ) { totalTime += times3 [ i ] . responseEnd - times3 [ i ] . fetchStart ; } return totalTime ; }
Calculates the union of durations of the specified resources.
Calculates the union of durations of the specified resources .
// First, sort by start time, then end time // Next, find all resources with the same start time, and reduce // them to the largest end time. // Third, for every resource, if the start is less than the end of // any previous resource, change its start to the end.  If the new start // time is more than the end time, we can discard this one. // as long as this resource has > 0 duration, add it to our next list // keep track of the furthest end point // Reduce down again to same start times again, and now we should // have no overlapping regions // Finally, calculate the overall time from our non-overlapping regions