Member Avatar for apeiron27

hi
i have this line in my code that seems to slow down as my loop progresses..

for i in range(start, end):
nPack = struct.pack('<I',i)

at first it takes about 0.00something second but later it starts to take like 0.12 sec.
i have huge no of different start and end pair so that is a big slow down.
has this happened to anyone before?
any idea what might be slowing down my program?

Recommended Answers

All 2 Replies

Explain what you are trying to do, and post whole relevant function. Probably you have wrong algorithm for the job. Also maybe you should be using xrange if the length of the range is big and you use Python 2. In my computer struct.pack() looks like taking around 0.88 microseconds.

"Why is this taking so long" is a question that is too general for you to answer. So learn to use profiling. The first few sentences read
"The first step to speeding up your program is learning where the bottlenecks lie. It hardly makes sense to optimize code that is never executed or that already runs fast. I use two modules to help locate the hotspots in my code, profile and trace."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.