Sobes.tech
Junior

// What will the following program output and how long will it run? package main import ( "fmt" "time" ) const numRequests = 10000 var count int func networkRequest() { time.Sleep(time.Millisecond) // Emulating a network request. count++ } func main() { for i := 0; i < numRequests; i++ { networkRequest() } fmt.Println(count) }

sobes.tech AI

Answer from AI

The program will perform 10,000 iterations, each calling the networkRequest function, which pauses for 1 millisecond and increments the global variable count.

The program output will be:

10000

The execution time is approximately:

  • Each iteration takes about 1 millisecond (due to time.Sleep(time.Millisecond))
  • There are 10,000 iterations in total
  • Therefore, the total time is about 10,000 milliseconds, or roughly 10 seconds.

The program runs sequentially, without parallelism, so the time adds up.

// What will the following program output and how… - sobes.tech