Skip to content

Instantly share code, notes, and snippets.

@lfender6445
Created September 10, 2013 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfender6445/6514498 to your computer and use it in GitHub Desktop.
Save lfender6445/6514498 to your computer and use it in GitHub Desktop.
stress test for leads
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