1

I wrote this simple code (in python) in test.py. I try to run timeit and I don't have any errors but I don't get any information about the time of run. Can you help me ?

import timeit

def functionsWhile():
    "Desc about function"
    lic = 0
    n = 30000
    while lic<= n:
            lic += 1
    #print "test"
    return lic

t = timeit.Timer("functionsWhile()", "from __main__ import functionsWhile")

try:
    t.repeat(3, 2)
except:
    t.print_exc()

I expect a result such as (EXAMPLE):

$>python test.py
[0.006793975830078125, 0.006793975830078125, 0.006793975830078125]
$>

But I have only:

$>python test.py
$>

I don't have result from timeit. I use python 2.7 and linux.

rantanplan
  • 7,283
  • 1
  • 24
  • 45
Bartosz Kowalczyk
  • 1,479
  • 2
  • 18
  • 34
  • 1
    Yeah, just typing the variable name only works in the interactive interpreter but not when run as a script. – jamylak May 06 '12 at 15:54
  • 1
    "just typing the variable name only works in the interactive interpreter but not when run as a script." That's how the interpreter works for _everything_ that returns a value. Try putting a plain "Hello" in the interactive interpreter and in a script, for example. – alexis May 06 '12 at 16:10
  • 1
    Your code is giving the desired `output` in python interpreter.So, you are definitely missing a `print` statement. – RanRag May 06 '12 at 16:12

1 Answers1

7

Try to print the result of t.repeat.

jamylak
  • 128,818
  • 30
  • 231
  • 230
XORcist
  • 4,288
  • 24
  • 32