Created
December 10, 2014 16:20
-
-
Save Vasfed/b5566a0fdfe9dda9e3ca to your computer and use it in GitHub Desktop.
Averages for goalsmashers css bench results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add averages to http://goalsmashers.github.io/css-minification-benchmark/ | |
//use jquery | |
var body = document.getElementsByTagName("body")[0]; | |
var script = document.createElement('script'); | |
script.type = "text/javascript"; | |
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; | |
var f = function(){ | |
$ = jQuery; | |
$('tr').each(function(tr_i, tr){ | |
if (tr_i ==0) return; | |
var byte_sizes = $.map($('td:not(:first-child)', tr), function(v){ return parseInt($(v).text())}).filter(function(a){ return a > 0}); | |
var average = Math.ceil(byte_sizes.reduce(function(a,b){ return a+b}, 0) / byte_sizes.length) | |
console.log(tr_i, "avg", average) | |
$('td', tr).each(function(td_i, td){ | |
if(td_i == 0){ | |
$(td).append($('<br><span class="label label-default">'+average+'</span>')); | |
return; | |
} | |
var v = parseInt($(td).text()); | |
if(v == 0) return; | |
var cls = 'default', res = ((v / average)*100) - 100; | |
res = res.toFixed(2); | |
if(res < 0) cls = 'success'; | |
if(res > 0) cls = 'danger'; | |
$(td).append($('<br><span class="label label-'+cls+'">'+res+'</span>')); | |
}); | |
}); | |
}; | |
script.onload=f; | |
script.onreadystatechange=function () { | |
if (this.readyState == 'complete') f(); | |
} | |
body.appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment