[Python-Dev] SEEK_* constants in io and os (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Mon Sep 2 15:51:09 CEST 2013
- Previous message: [Python-Dev] SEEK_* constants in io and os
- Next message: [Python-Dev] SEEK_* constants in io and os
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Le Mon, 2 Sep 2013 15:45:22 +0200, Antoine Pitrou <solipsis at pitrou.net> a écrit :
Le Mon, 2 Sep 2013 06🔞31 -0700, Eli Bendersky <eliben at gmail.com> a écrit : > On Mon, Sep 2, 2013 at 1:24 AM, Antoine Pitrou <solipsis at pitrou.net> > wrote: > > > Le Sun, 1 Sep 2013 18:02:30 -0700, > > Eli Bendersky <eliben at gmail.com> a écrit : > > > Hello, > > > > > > I was looking at the possibility of replacing the SEEK* > > > constants by IntEnums, and the first thing that catches > > > attention is that these constants are defined in both Lib/os.py > > > and Lib/io.py; both places also recently started supporting > > > SEEKHOLE and SEEKDATA (though here io refers to os.SEEKHOLE > > > and os.SEEKDATA). > > > > What is the runtime cost of doing so? os is a fundamental module > > that is imported by almost every Python program. > > > > Theoretically, it should be very low given that we just need to add > an import and define one class. os already does a number of things > in its toplevel (mostly a few imports which transitively do other > things). Compounded with import caching, since this is done just > once per run, doesn't seem like a problem. > > Empirically, I tried measuring it but I can't discern a difference > with/without translating SEEK* to enums. There's a fluctuation of > ~1usec which I can't distinguish from noise. Let me know if you have > a good methodology of benchmarking these things
How did you get that result? You have to remove to "os" from sys.modules before importing it again, otherwise "import os" will simply return the already imported module.
Oh and remove "enum" too...
Regards
Antoine.
- Previous message: [Python-Dev] SEEK_* constants in io and os
- Next message: [Python-Dev] SEEK_* constants in io and os
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]