473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Presumably an import is no faster or slower than opening a file?

I'm trying to minimise the overheads of a small Python utility, I'm
not really too fussed about how fast it is but I would like to
minimise its loading effect on the system as it could be called lots
of times (and, no, I don't think there's an easy way of keeping it
running and using the same copy repeatedly).

It needs a configuration file of some sort which I want to keep
separate from the code, is there thus anything to choose between a
configuration file that I read after:-

f = open("configFile", 'r')

.... and importing a configuration written as python dictionaries or
whatever:-

import myConfig

--
Chris Green
Apr 6 '08 #1
2 1056
On 6 avr, 15:41, tinn...@isbd.co.uk wrote:
I'm trying to minimise the overheads of a small Python utility, I'm
not really too fussed about how fast it is but I would like to
minimise its loading effect on the system as it could be called lots
of times (and, no, I don't think there's an easy way of keeping it
running and using the same copy repeatedly).

It needs a configuration file of some sort which I want to keep
separate from the code, is there thus anything to choose between a
configuration file that I read after:-

f = open("configFile", 'r')

... and importing a configuration written as python dictionaries or
whatever:-

import myConfig
In both cases, you'll have to open a file. In the first case, you'll
have to parse it each time the script is executed. In the second case,
the first import will take care of compiling the python source to byte-
code and save it in a myConfig.pyc file. As long as the myConfig.py
does not change, subsequent import will directly use the .pyc, so
you'll save on the parsing/compiling time. FWIW, you can even
"manually" compile the myConfig.py file, after each modification, and
only keep the myConfig.pyc in your python path, so you'll never get
the small overhead of the "search .py / search .pyc / compare
modification time / compile / save" cycle.

While we're at it, if you worry about the "overhead" of loading the
conf file, you'd better make sure that either you force the script
compilation and keep the .py out of the path, or at least keep the
script.py file as lightweight as possible (ie : "import somelib;
somelib.main()", where all the real code is in somelib.py), since by
default, only imported modules get their bytecode saved to .pyc file.

Now I may be wrong but I seriously doubt it'll make a huge difference
anyway, and if so, you'd really preferer to have a long running
process to avoid the real overhead of launching a Python interpreter.

My 2 cents...
--
Chris Green
Apr 6 '08 #2
br*****************@gmail.com <br*****************@gmail.comwrote:
On 6 avr, 15:41, tinn...@isbd.co.uk wrote:
I'm trying to minimise the overheads of a small Python utility, I'm
not really too fussed about how fast it is but I would like to
minimise its loading effect on the system as it could be called lots
of times (and, no, I don't think there's an easy way of keeping it
running and using the same copy repeatedly).

It needs a configuration file of some sort which I want to keep
separate from the code, is there thus anything to choose between a
configuration file that I read after:-

f = open("configFile", 'r')

... and importing a configuration written as python dictionaries or
whatever:-

import myConfig

In both cases, you'll have to open a file. In the first case, you'll
have to parse it each time the script is executed. In the second case,
the first import will take care of compiling the python source to byte-
code and save it in a myConfig.pyc file. As long as the myConfig.py
does not change, subsequent import will directly use the .pyc, so
you'll save on the parsing/compiling time. FWIW, you can even
"manually" compile the myConfig.py file, after each modification, and
only keep the myConfig.pyc in your python path, so you'll never get
the small overhead of the "search .py / search .pyc / compare
modification time / compile / save" cycle.

While we're at it, if you worry about the "overhead" of loading the
conf file, you'd better make sure that either you force the script
compilation and keep the .py out of the path, or at least keep the
script.py file as lightweight as possible (ie : "import somelib;
somelib.main()", where all the real code is in somelib.py), since by
default, only imported modules get their bytecode saved to .pyc file.

Now I may be wrong but I seriously doubt it'll make a huge difference
anyway, and if so, you'd really preferer to have a long running
process to avoid the real overhead of launching a Python interpreter.
Thanks for the comments, mostly about what I was thinking too but I
just wanted to check that I'm not missing anything really obvious.

--
Chris Green
Apr 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Demetris | last post by:
Hello people! I have a table with more than 30 million rows,a lot of columns and indexes. We need to change a column which is dec(15,2) and nullable to have a default value of zero. As I know you...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
10
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has...
3
by: Tony | last post by:
With respect to the questions below, please assume that our database(s) and all text files are shared on a network file server. When opening a shared MDB, what is the effect of its accessing data...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
16
by: Jon Davis | last post by:
We ordered new systems with fast hardware and great specs, but Visual Studio takes longer to build a project than on the old workstation. Msbuild is faster, csc.exe is faster, file copy is faster....
8
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
Could you please help me in this project. I have aTab delemeted file. It has 20 columns and some data. I have to import this data into SQL Server. I am using sql express edition. I am using...
41
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
5
by: DR | last post by:
Why is its substantialy slower to load 50GB of gzipped file (20GB gzipped file) then loading 50GB unzipped data? im using System.IO.Compression.GZipStream and its not maxing out the cpu while...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.