Most efficient way to write data out to a text file?
bokr at oz.net
Sat Jun 29 17:38:41 EDT 2002
On Sat, 29 Jun 2002 19:05:18 GMT, "Fredrik Lundh" <fredrik at pythonware.com> wrote:
>Dave Kuhlman wrote:
>> Is finding things in globals slower than finding them in locals?
>yes. Python assigns integer indices to local names, and
>stores the corresponding objects in an array.
Is this done for built-in keywords also? ISTM a standard list
of indices could be defined for a particular Python version,
and code generated to take advantage.
Maybe even a range of byte codes could be reserved for much-used
functions, as opposed to looking them up and then executing
a general function-call byte code to go there. It should be
possible to make this an efficient default, while still allowing
for straight-forward local shadowing bindings, IWT.
E.g., instead of the code for abs(x) being
3 LOAD_NAME 0 (abs)
6 LOAD_NAME 1 (x)
9 CALL_FUNCTION 1
it might be
6 LOAD_NAME 1 (x)
9 CALL_BUILTIN_0 1
where e.g. CALL_BUILTIN_0 .. CALL_BUILTIN_31 might be the reserved range
for builtin functions in the special list.
3 LOAD_NAME 0 (x)
6 LOAD_CONST 0 (0)
9 CALL_BUILTIN_X 1
would probably be about as fast, though not as compact.
If necessary to make it unambiguous and to make compilation easier, you could have
a "builtin" declaration analogous to "global." Or the usage might be popular enough
that you'd want a way to opt out instead of opt in. Since it's a bad idea to rebind
keywords anyway, maybe backwards compatibility wouldn't be too much of a problem if
it were default for some builtins functions in a future version?
Hm, seems like you could do static arg count checks too for this kind of builtin use.
Hm2, wonder if you could allow user-defined assignment of functions to dynamically
assigned byte codes within a user range using "builtin user_func" declarations,
so that compilation would make analogous code like that suggested for real builtins.
OTTOMH just now, not exactly PEP-ready ;-)
More information about the Python-list