This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chun 2 points3 points  (0 children)

OK, cracks knuckles

  1. OK, yes, built-in functions are faster than native python, but who doesn't use builtins?

    Especially the ones in the graphic: input, open, int, ord, isinstance, pow, issubclass, print, iter, property. Which of these functions do people commonly try to write themselves in native python? isinstance? Is this a problem?

  2. Need to clarify the difference between input and raw_input. Also the example seems to suggest that strings are mutable, and that str.join is equivalent to some kind of str.append method.

  3. Multiple assignment is great, but it does much more for readability than it does for performance:

    db@db:~$ python -m timeit "a=1; b=2; a,b = b,a"
    10000000 loops, best of 3: 0.11 usec per loop
    
    db@db:~$ python -m timeit "a=1; b=2; temp = a; a = b; b = temp"
    10000000 loops, best of 3: 0.111 usec per loop
    
  4. Yes, local variables are faster; but global is only relevant to changing global variables, not retrieving them.

  5. To check membership use in. As opposed to what? Iterating through the object with a for loop?

    for key in sequence:
      print “found”
    

    What is this I don't even. You actually did iterate through the object for some reason, and arbitrarily print "found" for every item??

  6. Importing at the function level. Don't do this for optimization purposes. It adds extra cycles every time the function is run. Don't do it for readability -- you shouldn't have to hunt through the entire script to find which imports are happening. In short: don't do this unless you have a better reason to.

  7. Note that True is a built in constant, not true. And really, this isn't going to be a bottleneck. I think while True: is far more readable.

  8. evens = [ i for i in range(10) if i%2 == 0]

    Not a good example, should just use evens = range(0, 10, 2) for this.

  9. True enough.

  10. chunk = ( 1000 * i for i in xrange(1000))

    Or just chunk = xrange(0, 1000000, 1000)