g | x | w | all
Bytes Lang Time Link
081Swift 6250425T222145ZmacOSist
043Raku Perl 6 rakudo250422T195039Zxrs
035Ruby rbenchmark250331T163132ZJordan
080Nim250327T080827ZjanAkali
051Tcl170115T235123Zsergiol
027Powershell170114T204430Zcolsw
125Java 7170119T162226ZKevin Cr
023Japt170118T174521ZETHprodu
060Forth170118T204515Zmbomb007
072Racket170114T202739ZSven Hoh
036SAS170118T200850ZJ_Lard
094Clojure170118T012004ZCarcigen
075Gura170117T165051ZSygmei
0478th170114T184422ZChaos Ma
059JavaScript ES6170114T174430ZGeorge R
042Bash +coreutils170114T190316Zzeppelin
133C170115T004003ZAbel Tom
019Pyth170116T094513ZNepho
047Lua170115T225915ZATaco
073Groovy170114T205929ZGurupad
023Matlab170114T233428ZOwen Mor
070PHP170114T170008ZTitus
092SimpleTemplate170115T145949ZIsmael M
022TIBasic170115T132317ZJulian L
124ForceLang170115T124755ZSuperJed
043Bash + GNU utils170114T173036ZDigital
077Scala170115T032420Zjaxad012
013Noodel170115T001253Ztkellehe
261C++170115T003516Zuser6428
014Pyth170114T191343ZGurupad
051Mathematica170114T202115ZJungHwan
073Python 3.5170114T173635ZGurupad
022J170114T200610Zmiles
042R170114T193450ZSven Hoh
013MATL170114T185739ZLuis Men
034QBIC170114T191122Zsteenber
123C#170114T190130ZCarra
nan170114T181023ZBrad Gil
018CJam170114T182341ZDennis
060JavaScript170114T174726Znicael
023Octave170114T170141ZStewie G
066R170114T181129ZBillywob

Swift 6, 81 bytes

print(ContinuousClock().measure{(-1000...1000).map{print($0)}} / .seconds(1)*1e3)

Yes, the spaces around / are needed -- otherwise Swift tries to parse it as postfix instead of infix.

Raku (Perl 6) (rakudo), 43 bytes, 36 chars

$/=now;.say for -Ⅿ..Ⅿ;say (now -$/)*Ⅿ

Attempt This Online!

Using roman numeral M for 1000.

Ruby -rbenchmark, 35 bytes

p Benchmark.measure{p *-1000..1000}

Attempt This Online!

Prints the time in this format:

#<Benchmark::Tms:0x000073658a0605c8 @label="", @real=0.0030826888978481293, @cstime=0.0, @cutime=0.0, @stime=0.000392, @utime=0.002352000000000007, @total=0.002744000000000007>

...where @real is the elapsed real time in seconds as a float.

Benchmark.realtime would print just the number, but would cost an extra byte.

Ruby, 38 bytes

t=Time.now
p *-1000..1000
p Time.now-t

Attempt This Online!

Prints the elapsed time as a float number of seconds.

The last two lines could be combined into p *-1000..1000,Time.now-t for a 2-byte savings but I don't think that would reflect the actual amount of time to print the numbers since the time would be calculated before the actual printing happens.

Nim, 80 bytes

import times
var t=now()
for n in-1000..1000:echo n
echo inMilliseconds(now()-t)

Try it online!

Tcl, 51 bytes

set i -1001
puts [time {time {puts [incr i]} 2001}]

Try it online!

Note: The answer is given as microseconds per iteration — The iterations here indicated belong to the outermost time command, which are implicitly 1 when its iterations parameter is omitted, which is the case; and not about the loop iterations!

Powershell, 27 Bytes

$1=date;-1e3..1e3;(date)-$1

Thanks to AdmBorkBork for pointing out that the verbose default output is acceptable in the challenge.

Outputs result like:

994
995
996
997
998
999
1000

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 5
Milliseconds      : 679
Ticks             : 56799255
TotalDays         : 6.57398784722222E-05
TotalHours        : 0.00157775708333333
TotalMinutes      : 0.094665425
TotalSeconds      : 5.6799255
TotalMilliseconds : 5679.9255

for more contained result of just milliseconds, use original answer:

$1=date;-1e3..1e3;((date)-$1).TotalMilliseconds

Save time before as $1, print to stdout automatically, then get the time between the beginning and end of execution.

Java 7, 125 bytes

void c(){long x=System.nanoTime(),i=-1001;for(;i<1e3;)System.out.println(++i);System.out.println((System.nanoTime()-x)/i/i);}

Ungolfed:

void c() {
  long x = System.nanoTime(),
       i = -1001;
  for(; i < 1e3; ){
    System.out.println(++i);
  }
  System.out.println((System.nanoTime() - x) / i / i);
}

Test code:

Try it here.

class M{
  static void c(){long x=System.nanoTime(),i=-1001;for(;i<1e3;)System.out.println(++i);System.out.println((System.nanoTime()-x)/i/i);}

  public static void main(String[] a){
    c();
  }
}

Example output:

-1000
-999
...
...
...
999
1000
13

Japt, 23 bytes

There are two equivalent solutions:

Oo(Ð -(A³òA³n @OpXÃ,йn
K=Ð;A³òA³n @OpXÃ;OoÐ -K

The first one basically does the following:

output(-(new Date() - (1000 .range(-1000).map(X => print(X)), new Date())));

That is, the numbers are printed in the middle of the subtraction to avoid having to store the time in a variable. However, it's not any shorter than the variable route, which is basically:

K = new Date(); 1000 .range(-1000).map(X => print(X)); output(new Date() - K);

In the latest version of Japt (newer than this challenge), K is set up to automatically return new Date(). This cuts the first solution down to 21 bytes:

Oo(K-(A³òA³n @OpXÃK)n

Test it online!

Forth, 60 bytes

utime - Report the current time in microseconds since some epoch.

utime
: f 1001 -1000 do I dup . CR loop ; f
utime - 1000 / .

Racket, 72 bytes

(time(map(lambda(x)(display(exact-floor x))(newline))(range -1e3 1001)))

SAS, 36 bytes

Pretty straightforward, SAS prints out the time taken for a data step by default..

data c;do i=-1000 to 1000;put i;end;

Clojure, 94 bytes

(let[t #(System/currentTimeMillis)s(t)](doseq[n(range -1e3 1001)](println n))(println(-(t)s)))

I'm disappointed at how long this got, but I guess no one ever claimed Clojure was a good language to golf in.

Naïve solution that just records the starting time, loops, then prints the current time minus the starting time. Unless Clojure has a ms-time getter than I'm missing, I don't know how this could get any shorter. Maybe some kind of implicit loop?

(defn time-print []
  (let [t #(System/currentTimeMillis) ; Alias the time-getter to "t"
        start (t)] ; Record starting time
    (doseq [n (range -1000 1001)] ; Loop over the range...
      (println n)) ; ... printing the numbers

    (println (- (t) start)))) ; Then print the current time minus the starting time.

Gura, 75 bytes

t=datetime.now();println(-1000..1000);print((datetime.now()-t).usecs/1000);

8th, 61 47 bytes

Thanks to 8th_dev for nice improvement (saved 14 bytes)

d:msec ( . cr ) -1000 1000 loop d:msec swap - .

This will print all the integer numbers between -1000 and 1000 in ascending order and the time taken (in milliseconds) to print these numbers

-1000
-999
-998
-997
...
997
998
999
1000
4

JavaScript (ES6), 63 59 bytes

for(c=console.log,i=~1e3;i<1e3;c(++i));c(performance.now())

Bash (+coreutils), 41, 49, 46, 44, 42 bytes

EDITS:

Golfed

TIMEFORMAT=%R*1000;(time seq -1e3 1e3)|&bc

Try It Online !

Sidenote

Using a coreutils "time" utility, instead of the Bash-builtin, results in a 41, 35 byte solution:

\time -f "%e*1000" seq -1e3 1e3|&bc

"\" is here to make bash invoke the real command, instead of the builtin.

Unfortunately coreutils time precision is only 1/100s, which have raised concerns on if it is a valid solution.

C 134 133 bytes

Thanks to @Thomas Padron-McCarthy for saving 1 byte.

f(){clock_t s,e;s=clock();for(int i=-1000;i<1001;i++)printf("%d\n",i);e=clock();printf("%lf",((double)((e-s))/(CLOCKS_PER_SEC))*1e3);}

Ungolfed version :

void f()
{   
  clock_t s,e;

  s=clock();

  for(int i=-1000;i<1001;i++)
    printf("%d\n",i);   

  e=clock();
  printf("%f",((double)((e-s))/(CLOCKS_PER_SEC))*1e3);

 }

Pyth, 19 bytes

Edit: So apparently .d1 is the process time. Saved 6 bytes.

Edit: .d1 is the process time in µseconds, so I have to multiply it by 1000.

K^T3FNr_KhKN;*K.d1

This is a naive solution that pretty much does what's asked without any trick. I'm a beginner with Pyth and still getting the hang out of it. Any suggestion would be very appreciated!

Explanation

K^T3FNr_KhKN;*K.d1
K^T3                     Assigns 10^3 to K
    FNr_KhK              Loops on N from -1000 to 1000
           N;            Each loop, print N
             *K.d1       Prints process time * 1000

Lua, 47 Characters

for i=-1e3,1e3 do print(i)end print(os.clock())

It's nice and simple, a basic printing for loop from -1e3 to 1e3, then just print the os.clock, which is conveniently the ms since program execution.

Groovy, 75 73 bytes

t=System.&nanoTime
s=t()
(-1000..1e3).each{println it}
print((t()-s)/1e6)

Thanks to jaxad0127 for saving 2 bytes!

Try it here !

Matlab, 16 23 Bytes

tic;(-1e3:1e3)'
toc*1e3

Edit: I realised I was violating several of this challenge's rules. That'll teach me to skim read the challenge late at night. I also now realise that the corrected answer is almost identical to the Octave solution, but such is life.

Prints each element in the created linear space array -1000:1000 (the lack of ; prints to console).

tic/toc records the time and toc prints the time to the console with or without the ; . 1e3 is needed to print in milliseconds.

PHP, 110 70 bytes

still a little long; but saved 38 with @AlexHowansky´s hint, and two more with 1e3 and ~1e3.

for($t=($m=microtime)($i=~1e3);$i++<1e3;)echo"$i
";echo($m(1)-$t)*1e3;

prints float. Run with -r.

SimpleTemplate, 92 bytes

What really killed me was the need to record the time.

{@callmicrotime intoX 1}{@for_ from-1000to1000}{@echol_}{@/}{@phpecho microtime(1)-$DATA[X]}

Since there's no math (yet), this makes things pretty hard, forcing me to write PHP directly.

Ungolfed:

{@call microtime into start_time true}
{@for i from -1000 to 1000 step 1}
    {@echol i}{@// echoes a newline after}
{@/}
{@php echo microtime(true) - $DATA["start_time"];}

Disclaimer:

I've ran this with the commit e118ae72c535b1fdbe1b80c847f52aa161854fda, from 2017-01-13.

The latest commit was to fix something that is un-related to the code in here.

TI-Basic, 22 bytes

startTmr
For(A,-ᴇ3,ᴇ3
Disp A
End
startTmr-Ans

ForceLang, 124

set t timer.new()
set i -1000
label 1
io.writeln set i i+1
if i=1000
 io.write math.floor 0.001.mult t.poll()
 exit()
goto 1

Note: You should supress stderr when running this. I believe the consensus on meta is that this does not incur a byte count penalty.

Bash + GNU utils, 43

c=date\ +%s%3N
s=`$c`
seq -1e3 1e3
$c-$s|bc

The date command gives the number of seconds since the epoch concatenated with current nanoseconds. This command is run before and after. bc takes the difference and prints.

Try it online.


I was hoping to do this for 17:

time seq -1e3 1e3

But the output of time gives more than we need:

real    0m0.004s
user    0m0.000s
sys 0m0.004s

Scala, 77 bytes

def t=System.nanoTime
val s=t
Range(-1000,1001)map println
println((t-s)/1e6)

Noodel, 17 13 bytes

13 bytes

Tried a slightly different approach and saved 4 bytes.

ƇQjȥḶGQɱ⁻Ñ€Ƈ⁻

Try it:)

How it works

Ƈ             # Pushes on the amount of milliseconds passed since 01/01/1970.

 Qjȥ          # Pushes 2001 onto the stack.
 Qj           # Pushes on the string "Qj"
   ȥ          # Converts the string into a number as base 98.

    ḶGQɱ⁻Ñ€   # Loops 2001 times printing -1000 to 1000.
    Ḷ         # Consumes the 2001 and loops the following code 2001 times.
     GQ       # Pushes on the string "GQ"
       ɱ      # Pushes on the current counter of the loop (i)
        ⁻     # Subtracts (i - "GQ") since i is a number, the "GQ" is converted to a number which will fail.
              # So, Noodel will treat the string as a base 98 number producing (i - 1000). 
         Ñ    # Consume what is on the top of the stack pushing it to the screen followed by a new line.
          €   # The end of the loop.

           Ƈ⁻ # Calculates the duration of execution.
           Ƈ  # Pushes on the amount of milliseconds passed since 01/01/1970.
            ⁻ # Pushes on (end - start)

17 bytes

ƇGQȥḋɲṡ×2Ḷñ⁺1€ÑƇ⁻

Try it:)

How it works

Ƈ                 # Pushes on the amount of milliseconds passed since 01/01/1970.

 GQȥḋɲṡ×2         # Used to create the range of numbers to be printed.
 GQ               # Pushes on the string "GQ".
   ȥ              # Converts the string into number as if it were a base 98 number. (which is 1000)
    ḋ             # Duplicates the number and pushes it onto the stack. 
     ɲ            # Since the item on top is already a number, makes the number negative (random thing I threw in at the very beginning when made the langauge and totally forgot it was there)
      ṡ           # Swaps the first two items on the stack placing 1000 on top.
       ×2         # Doubles 1000 producing... 2000

         Ḷñ⁺1€Ñ   # Prints all of the numbers from -1000 to 1000.
         Ḷ        # Consumes the 2000 to loop the following code that many times (now -1000 is on the top).
          ñ       # Prints the value on top of the stack followed by a new line.
           ⁺1     # Increment the value on top of the stack by 1.
             €    # End of the loop.
              Ñ   # Since 1000 is still not printed, this consumes 1000 and prints it followed by a new line.

               Ƈ⁻ # Calculates the number of milliseconds to execute program.
               Ƈ  # Pushes on the amount of milliseconds passed since 01/01/1970.
                ⁻ # Pushes on (end - start) in milliseconds.
                  # At the end, the top of the stack is pushed to the screen.

The snippet uses the values -4 to 4 in order to not take so long to complete.

<div id="noodel" code="ƇFȥḶAɱ⁻Ñ€Ƈ⁻" input="" cols="10" rows="10"></div>

<script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>

C++ - 261

Just for a laugh I thought I'd post a C++ answer.

#include <iostream>
#include <chrono>
using namespace std::chrono; using c=std::chrono::system_clock; void p(){c::time_point n=c::now();for(int i=-1001;++i<1001;)std::cout<<i<<"\n";std::cout<<(duration_cast<milliseconds>(system_clock::now()-n)).count()<<"\n";}

I'll leave it as an exercise to determine what it is doing and how to call it - shouldn't be too difficult.

Pyth, 18 15 14 bytes

j}_J^T3J;*.d1J

Try it here!

Explanation

This is similar to my python answer.

    J^T3           Set J to 1000
  }_    J         List ranging from -1000 to 1000
j                 Join the list with new lines and implicitly print it
         ;*.d1J   Print time since execution of the program in milliseconds

Edits:

Mathematica, 51 bytes

p[1*^3#]&@@AbsoluteTiming@Array[p=Print,2001,-1*^3]

Explanation

Array[p=Print,2001,-1*^3]

Store the Print function in p. Print 2001 numbers, starting at -1000, incrementing by 1.

AbsoluteTiming@ ...

Find the total time elapsed in seconds.

p[1*^3#]&@@ ...

Multiply that by 1000 (seconds -> miliseconds) and p (Print) it.

Python 3.5, 80 77 73 bytes

import time
*map(print,range(-1000,1001)),
print(time.process_time()*1e3)

Previous solutions involved using timeit and time.time(), they were larger.

Sadly, time.process_time() was introduced in python 3.3.

Thanks to Dennis for saving 4 bytes!

J, 22 bytes

1e3*timex'echo,.i:1e3'

Try it online!

timex is a builtin that executes the string and returns the time it took to evaluate it in seconds. The string forms the range [-1000, 1000] using i:, then columinizes it using ,., and prints it using the builtin echo.

R, 42 bytes

system.time(cat(-1e3:1e3,sep="\n"))[3]*1e3

This will print

.
.
.
998
999
1000
elapsed 
     60 

To remove elapsed, two additional bytes are necessary:

system.time(cat(-1e3:1e3,sep="\n"))[[3]]*1e3

MATL, 13 bytes

1e3t_y&:!DZ`*

Try it online!

       % Implicitly start timer
1e3    % Push 1000
       % STACK: 1000
t_     % Duplicate, negate
       % STACK: 1000, -1000
y      % Duplicate second-top number
       % STACK: 1000, -1000, 1000
&:     % Two-input range
       % STACK: 1000, [-1000, 999, ..., 1000]
!      % Transpose into column vector
       % STACK: 1000, [-1000; 999; ...; 1000]
D      % Display
       % STACK: 1000
Z`     % Push timer value, say t
       % STACK: 1000, t
*      % Multiply
       % STACK: 1000*t
       % Implicitly display

QBIC, 34 bytes

d=timer[-z^3,z^3|?a]?z^3*(timer-d)

Uses the QBasic TIMER function, which returns seconds in decimal notation. Making it look pretty adds some bytes.

Explanation

d=timer     Set 'd' to the current # seconds since midnight
[-z^3,z^3|  FOR -1000 to 1000  --  Note that 'z' = 10 in QBIC, and z^3 saves a byte over 1000
?a          Display the iterator
]           Close the FOR loop
    timer-d Take the current time minus the time at the start of the program -- 0.156201
?z^3*()     Multiply by a thousand and display it   156.201

C# - 123

This isn't going to win anything but hey, here it goes :)

()=>{var t=DateTime.Now;var s="";for(int i=-1000;i<1001;i++)s+=i+"\n";Console.WriteLine(s+(DateTime.Now-t).Milliseconds);};

Run like this:

Action y = ()=>{var t=DateTime.Now;var s="";for(int i=-1000;i<1001;i++)s+=i+"\n";Console.WriteLine(s+(DateTime.Now-t).Milliseconds);};
y();

Perl 6, 45 bytes

.put for -($_=1e3)..$_;put (now -INIT now)*$_

Try it

Expanded:

# print the values

.put             # print with trailing newline ( method call on 「$_」 )

for              # for each of the following
                 # ( temporarily sets 「$_」 to the value )

-(
  $_ = 1e3       # store 「Num(1000)」 in 「$_」
)
..               # inclusive Range object
$_;

# print the time elapsed

put              # print with trailing newline

(now - INIT now) # Duration object that numifies to elapsed seconds
* $_             # times 1000 to bring it to milliseconds

# The 「INIT」 phaser runs code (the second 「now」) immediately
# as the program starts.

# There is no otherwise unrelated set-up in this code so this is a
# reliable indicator of the amount of time it takes to print the values.

CJam, 18 bytes

es2001{1e3-n}/es\-

Try it online!

How it works

es                  Push the current time (milliseconds since epoch) on the stack.
  2001{     }/      For each integer X from 0 to 2000:
       1e3-           Subtract 1000 from X.
           n          Print with a newline.
              es    Push the current time on the stack.
                \-  Swap and subtract.

JavaScript, 60 bytes

(c=console).time();for(i=~1e3;i++<1e3;c.log(i));c.timeEnd();

In order to get all the events logged, you should use the script from the developer console (otherwise the logs are erased after the certain amount of them).

Octave, 46 43 36 30 23 bytes

tic;(-1e3:1e3)',toc*1e3

This will print:

ans =

  -1000
   -999
   -998
   -997
   -996
   -995

If you don't like the ans = , then we have to add an additional 6 bytes for disp:

tic;disp((-1e3:1e3)'),toc*1e3

Saved a lot of bytes thanks to a few reminders from rahnema1.

Explanation:

tic;                              % Starts timer
         (-1e3:1e3)'              % A vertical vector -1000 ... 1000
    disp((-1e3:1e3)'),            % Display this vector
                      toc*1e3     % Stop the timer and output the time in milliseconds

R, 66 bytes

x=proc.time();for(i in -1e3:1e3)cat(i,"\n");(proc.time()-x)[3]*1e3

Probably not the shortest but it works.