Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 2
    A quick thought: numpy.array is actually a more complex data structure than a list. And in the second snippet, you create a list and an numpy array (in the first only a list). Whether this is the only reason for such a big difference, I cannot say. Commented Jul 2, 2011 at 20:38
  • @Felix: ok, but the creation of the list is fast, so even if I create a list and a numpy array in the second case, it's still the numpy creation that is the hot spot here, and regardless how complex the structure may be, it's still damn expensive... Commented Jul 2, 2011 at 20:40
  • 3
    But consider: Creating the data is rarely the bottleneck in an application that so complex it uses numpy. I don't know what happens under the hood either, but it obviously makes math-heavy programs faster at the end of the day, so there's no reason to complain ;) Commented Jul 2, 2011 at 20:49
  • 7
    @Stefano: aren't you including the import of numpy in the timings? (Also python has a builtin timings module.) Commented Jul 2, 2011 at 21:09
  • 1
    Just quick tip, you can use python -mtimeit test.py to do benchmarking. Commented Jul 2, 2011 at 21:21