Skip to content

Instantly share code, notes, and snippets.

@deepakshrma
Created July 2, 2016 21:11
Show Gist options
  • Save deepakshrma/a9076108696860e8546caf7ba9702176 to your computer and use it in GitHub Desktop.
Save deepakshrma/a9076108696860e8546caf7ba9702176 to your computer and use it in GitHub Desktop.
Explaining sync code and slow io operation
var alert = console.info;
console.time('APP_CALL');
function firstAPI() {
alert('first api call');
var i =0;
var looptillIndex_sm =1000000;
var looptillIndex_lg =1000000000;
console.time('API_CALL')
//SyncIo
while(i < looptillIndex_lg-1){
//while(i < looptillIndex_sm-1){
//one of the worst thing that you can do...Log...
if(i%1000000 ==0) console.log("i m here..", i);
i++;
}
console.timeEnd('API_CALL')
}
function secAPI() {
alert('sec api call...');
console.timeEnd('APP_CALL');
}
setTimeout(firstAPI, 1000);
setTimeout(secAPI, 1002);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment