title: Why does two small for-loops run faster than a big one ? published: true description: tags: explainlikeimfive, discussion, javascript


Explain Like I am five Why does two small for loops run faster than one big for loop?

``` s = Date.now() for(let i=0;i<1e10;i++) { i + 100 } for(let i=0;i<1e10;i++) { i + 100 } console.log(Date.now() - s) // => 37s

s = Date.now() for(let i=0;i<2e10;i++) { i + 100 } console.log(Date.now() - s) // => 38s

```

Especially for language like JS which is not multi-threaded