Last active
March 21, 2024 14:02
-
-
Save kschaper/cf96bb7475b833446ed93dfcfae781c2 to your computer and use it in GitHub Desktop.
CPU friendly infinite loop in Go
This file contains hidden or 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
// CPU friendly | |
for { | |
select { | |
case <-time.After(time.Second): | |
// do something | |
} | |
} | |
// instead of busy loop | |
for { | |
time.Sleep(time.Second) | |
// do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.reddit.com/r/golang/comments/6ec9o2/effect_of_infinite_loop_on_cpumem/