id summary reporter owner description type status priority milestone component resolution keywords cc merged author reviewer upstream work_issues branch commit dependencies stopgaps
22412 "timeit(""..."") does not work inside a function" nthiery "Apparently, timeit('some expression') evaluates the expression in the
context of the interpreter rather than the local context where timeit
is being called, which can lead to unexpected results (some students
of mine got trapped today).
Let's take an example, where we time a non trivial factorization:
{{{
sage: p = (1-x^100)
sage: timeit('factor(p)', seconds=True)
0.007231048583984375
}}}
Now, let's do the same inside a function:
{{{
sage: def f(p):
....: return timeit('factor(p)', seconds=True)
sage: f(p) # That's normal
0.007200319290161133
sage: f(1) # OOPS, That should be instantaneous!
0.007200319290161133
}}}
I am not sure there is an easy fix, but at least this limitation needs
to be documented.
" defect new major sage-7.6 misc N/A