Commodore 64 BASIC, 1619 16 bytes
10 FOR I=1 TO1000 960FORI=1TO930*N:NEXT:RETURN
With a call N=<number-of-secods>:GOSUB1000
.
However, I cannot provide enough accuracy. Because C64 had about 1 MHz CPU speed, I remember it was good enough to make an empty FOR
-NEXT
loop 1000 times so that it was about 1 second.
In fact there were two main versions of the machine: PAL 0.985 MHz and NTSC 1.023 MHz (all data from C64 Wikipedia Page). As I had NTSC version, it was required to run loop about 950930 times.
Tests with the following program (5N
seconds, asprovided by user in the JINPUT
variable):
10 INPUT N
20 PRINT TI$
2030 FORGOSUB J=11000
40 TOPRINT 5TI$
3050 END
1000 FOR I=1 TO 960930*N:NEXT I
40 NEXT J
50 PRINT TI$:RETURN
where TI$
is a system variable containing string (hhmmss
format) with time elapsed from last reset (1 second accuracy, however also depending on CPU speed, so this is not quite relevant, because it's the same clock).
Screenshot made with online C64 emulator http://codeazur.com.br/stuff/fc64_final/.
This program (line 1000
only) occupies 1616 19 bytes in memory, as tested with PRINT FRE(0)+65535
both before typing the code (3890938908 bytes) and after (3889338893 38889 bytes). PRINT FRE(0)
returns free memory for BASIC program (it's a negative value and constant 65535
should be added, but in fact it does not matter).
Because this program does not test the time elapsed in a loop, it qualifies for a bounty.