Raymond Hettinger wrote: > Are you sure? The former has two builtin lookups (which also entail two > failed global lookups), a function call, and a test/jump for the result. > The latter approach has no lookups (just a load constant), a try-block > setup, an add operation (optimized for integers, a fast slot lookup > otherwise), and a block end. > > Even if there were a performance edge, I suppose that the type checking > is the time critical part of most scripts.
My guess is that it depends on the common case. If the common case is that the type test fails (i.e. element-wise operations are the exception), then you also have the exception creation and storing in the exception approach, compared to returning only existing objects in the type test case. If the common case is that x+0 succeeds, x+0 may or may not create new objects. However, I have long ago learned not to guess about performance, so I won't do further guessing until I see the actual code. Regards, Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com