Your game script is executed each game tick in a loop. The game tick duration depends on the current load of servers. The goal of a script is to process the current situation within the game and pass orders to your creeps and spawns. Commands are not executed instantly. Rather, the game remembers your commands and executes them later, after all players' scripts have been executed. For more details on this topic, see the article Understanding game loop, time and ticks.
Please remember that the exact duration of the execution of your script is limited by the CPU time available in your account. In case of exceeding the limit, the script execution will be stopped. The exception is the Simulation Room where the script execution time is unlimited.