Created
September 10, 2013 19:40
-
-
Save lfender6445/6514498 to your computer and use it in GitHub Desktop.
stress test for leads
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
var start, elapsed; | |
var load_times= []; | |
var init = function(){ | |
$('body').bind('finished', function(){ | |
elapsed = new Date() - start; | |
load_times.push(elapsed); | |
console.log("Elapsed time: " + elapsed); | |
}); | |
benchmark(); | |
}; | |
var average = function(a){ | |
var sum = 0; | |
for(var i = 0; i < a.length; i++){ | |
sum += parseInt(a[i]); | |
} | |
var avg = sum/a.length; | |
console.log("The average is: " + avg); | |
}; | |
var benchmark = function(){ | |
$('.link_check_availability:first').click(function(){ | |
start = new Date(); | |
watch_visibliy(); | |
average(load_times); | |
}); | |
}; | |
var watch_visibliy = function(){ | |
watch = setInterval(function(){ | |
if($('.popup_dialog .lead_form').is(':visible')){ | |
$('#check_availability .icon_close').click(); | |
$('body').trigger('finished'); | |
clearInterval(watch); | |
} | |
}, 1); | |
}; | |
var stress = function (){ | |
init(); | |
TIME = 3000; | |
CYCLES = 100; | |
var i = 0; | |
stress = setInterval(function(){ | |
$('.link_check_availability:first').click(); | |
if(i == CYCLES) { | |
clearInterval(stress); | |
} else { | |
i++; | |
} | |
}, TIME); | |
}; | |
stress(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment