<commit_before>/**
 * Measure when onDOMready and window.onload events are fired
 */
exports.version = '0.2';

exports.module = function(phantomas) {
	phantomas.setMetric('onDOMReadyTime');
	phantomas.setMetric('windowOnLoadTime');

	// emulate window.performance
	// @see https://github.com/ariya/phantomjs/issues/10031
	phantomas.on('init', function() {
		phantomas.evaluate(function() {
			(function(phantomas) {
				var start = Date.now();

				phantomas.spyEnabled(false, 'installing window.performance metrics');

				document.addEventListener("DOMContentLoaded", function() {
					phantomas.setMetric('onDOMReadyTime', Date.now() - start);
					phantomas.log('onDOMready');
				}, false);

				window.addEventListener("load", function() {
					phantomas.setMetric('windowOnLoadTime', Date.now() - start);
					phantomas.log('window.onload');
				}, false);

				phantomas.spyEnabled(true);
			})(window.__phantomas);
		});
	});
};<commit_msg>windowPerformance: compare time spent on backend and frontend<commit_after>/**
 * Measure when onDOMready and window.onload events are fired
 */
exports.version = '0.3';

exports.module = function(phantomas) {
	phantomas.setMetric('onDOMReadyTime');
	phantomas.setMetric('windowOnLoadTime');

	// emulate window.performance
	// @see https://github.com/ariya/phantomjs/issues/10031
	phantomas.on('init', function() {
		phantomas.evaluate(function() {
			(function(phantomas) {
				var start = Date.now();

				phantomas.spyEnabled(false, 'installing window.performance metrics');

				document.addEventListener("DOMContentLoaded", function() {
					phantomas.setMetric('onDOMReadyTime', Date.now() - start);
					phantomas.log('onDOMready');
				}, false);

				window.addEventListener("load", function() {
					phantomas.setMetric('windowOnLoadTime', Date.now() - start);
					phantomas.log('window.onload');
				}, false);

				phantomas.spyEnabled(true);
			})(window.__phantomas);
		});
	});

	/**
	 * Emit a notice with backend vs frontend time
	 *
	 * Performance Golden Rule:
	 * "80-90% of the end-user response time is spent on the frontend. Start there."
	 *
	 * @see http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/
	 */
	phantomas.on('report', function() {
		//  The “backend” time is the time it takes the server to get the first byte back to the client.
		//  The “frontend” time is everything else (measured until window.onload)
		var backendTime = parseInt(phantomas.getMetric('timeToFirstByte'), 10),
			frontendTime = parseInt(phantomas.getMetric('windowOnLoadTime'), 10),
			totalTime = backendTime + frontendTime,
			backendTimePercentage;

		if (totalTime === 0) {
			return;
		}

		backendTimePercentage = Math.round(backendTime / totalTime * 100);
		phantomas.addNotice('Time spent on backend / frontend: ' + backendTimePercentage + '% / ' + (100 - backendTimePercentage) + '%');
	});
};
{'fraction_non_alphanumeric': 0.14816099930603746, 'fraction_numerical': 0.012838306731436502, 'mean_word_length': 4.1852517985611515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7478775', 'n_tokens_mistral': 1024, 'n_tokens_neox': 864, 'n_words': 182}