# Time and switching tabs

**URL:** <https://forum.makecode.com/t/time-and-switching-tabs/519>\
**Category:** Arcade\
**Created:** [September 5, 2019, 10:00am UTC](https://forum.makecode.com/t/time-and-switching-tabs/519 "2019-09-05T10:00:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [September 5, 2019, 10:00am UTC](https://forum.makecode.com/t/time-and-switching-tabs/519/1 "2019-09-05T10:00:13Z")

</div>

How does time work in the simulator wrt switching tabs?

I’ve noticed that if I run the code mentioned in [Physics engine tests?](https://forum.makecode.com/t/physics-engine-tests/509) and switch to another tab in Chrome for a few seconds while the code is running it appears that the timer set by `start countdown` continues running but the code does not? Is that the intended behaviour?

If the simulator is intentionally pausing when the user goes off to use another tab in the same window then then shouldn’t it also [pause the simulator’s view of time](https://www.youtube.com/watch?v=Ag2Ihnwcb0c) for that duration?

---

<div class="post-metadata">

**Author:** ![gbraad](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gbraad/32/338_2.png) [@gbraad](https://forum.makecode.com/u/gbraad)\
**Post date:** [September 5, 2019, 3:34pm UTC](https://forum.makecode.com/t/time-and-switching-tabs/519/2 "2019-09-05T15:34:23Z")

</div>

This depends on the browser, but most browsers will assign less priority to background tabs (those that aren’t active). So I assume the simulator will be affected by this for sure. I do not think the simulator acts on being inactive (like pausing), but just runs with a lower priority … let someone correct me if I am wrong.

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [September 5, 2019, 4:34pm UTC](https://forum.makecode.com/t/time-and-switching-tabs/519/3 "2019-09-05T16:34:22Z")

</div>

I’m running the browser on a quiet multiprocessor desktop so there’s not an obvious lack of resources in play here.

On the subject of time, I’m also interested in another aspect. What does `time since start (ms)` return? Is this returning the simulation time in quanta related to the game loop or is it a free-running clock, i.e. successive calls within something like a large block of code in an `on game update` block are likely to return different values?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [September 5, 2019, 5:28pm UTC](https://forum.makecode.com/t/time-and-switching-tabs/519/4 "2019-09-05T17:28:35Z")

</div>

“Time since start” is the wall-clock time since the program began. It pauses if you are debugging (i.e. stepping through code, hitting breakpoints, etc.), but otherwise it is equal to the time that has elapsed in the browser/hardware clock since the program began.

The simulator doesn’t do anything special when you change tabs; it keeps running but is throttled by the browser. I believe all modern browsers always throttle background tabs.

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [September 5, 2019, 5:59pm UTC](https://forum.makecode.com/t/time-and-switching-tabs/519/5 "2019-09-05T17:59:19Z")

</div>

Thanks, perhaps I was being too impatient on letting it finish.

Chrome behaviour changes a lot with audio use. If I do a bit of continuous beeping then it will run when it’s not visible (user on another tab) at or close to normal speed, at least for that demo code I mentioned.
