# Print out execution time of program [closed]

## Challenge

Write a complete program that prints out the time it took to execute a certain part of itself. That part must include a process whose total number of operations (and therefore execution time) is dependent on a user-substituted numeric value - this can be denoted in any way in your code (uppercase N for example) and doesn't count as a byte.

Unlike many code golf challenges, this one is a valid use case - in environments that allow executing code from command line, you may want to have a short code snippet to roughly compare performance across different systems.

## Rules

• Execution time is denoted as a nonnegative integer or decimal value, followed by the corresponding time unit (let's accept ns, µs/us, ms, s, m and h). A space between the number and unit is optional, more spaces are also allowed (but not newline characters).
• Output must include the execution time exactly once. There can be additional text around it, as long as no part of it could be matched with the execution time itself. This allows using standard functions for timing code execution that may use various formats for printing out the execution time.
• Output goes to STDOUT. Anything in STDERR is disregarded.
• You can import any standard libraries before the actual code, without any cost to the total number of bytes, but you are not allowed to change the library name in the import declaration.
• Do not just use sleep to control the execution time, as that does not increase the number of operations (and also doesn't work as a performance benchmark). The execution time must also depend on the user-substituted value linearly, exponentially or polynomially (before you ask, a constant polynomial doesn't count).

## Scoring

This is code golf, so the shortest answer in bytes wins.

## Example

This is an unnecessarily long program written in Python:

import time

start_time = time.time()

for i in range(N):
pass

end_time = time.time()

print("%fs" % (end_time - start_time))

Program description:

• imports the standard time library (this adds no bytes to the code size)
• stores the current time in seconds
• loops N times, does nothing each iteration
• stores the time after the loop
• prints the time difference in the correct format
• Some potential examples would be great for this challenge, as that would help show people what their solution should look like. Jan 12, 2020 at 22:41
• @Jono2906 I added an example program in Python. Jan 12, 2020 at 23:12
• Rather than have N as some user substituted value, why not just say that it is given as input?
– Jo King
Jan 13, 2020 at 0:37
• Regarding input... of course different languages handle input differently? They also handle timing stuff differently, so that doesn't really seem like a valid excuse for why n can't just be input?
– Jo King
Jan 13, 2020 at 2:47
• Having said that, I agree it's better to use an actual input next time, since it's the default. Hard-coded inputs aren't allowed by default. So for next challenges I would indeed advice to follow @JoKing's suggestion and just having input. But for this challenge (considering the amount of answers) I would just leave it as hardcoded (non-counting) $n$ for now. Jan 13, 2020 at 10:11

If N is substituted in place of $1 (as described in the prompt), then 14 bytes. If N is given as an argument, then 16 bytes. time (: {0..$1})