473,573 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Different execution time in python code between embedded orstandalone

En Tue, 03 Jun 2008 16:58:12 -0300, Pau Freixes <pf******@milno u.net>
Hi list,

First Hello to all, this is my and hope not end message to the list :P

This last months I have been writting a program in c like to mod_python
embedding python language, it's a middleware for dispatch and execute
batch programs into several nodes. Now I'm writing some python program
test how scale this into several nodes and comparing with "standalone "

I found a very strange problem with one application named md5challenge,
aplication try to calculate the max number md5 digest in several seconds,
md5challenge use a simple signal alarm for stop program when time has
passed. This is the code of python script

def handler_alrm(si gnum, frame):
global _signal
global _nrdigest
global _f
_signal = True

def try_me():
global _nrdigest
global _f
global _signal

_f = open("/dev/urandom","r")
while _signal is not True:
buff = _f.read(_const_ b)
md5.md5(buff).h exdigest()
_nrdigest = _nrdigest + 1

if _f is not None :

def main( req ):
global _nrdigest
signal.signal(s ignal.SIGALRM, handler_alrm)
signal.alarm(re q.input['time'])

req.output['count'] = _nrdigest

return req.OK
if __name__ == "__main__":

# test code
class test_req:

req = test_req()
req.input = { 'time' : 10 }
req.output = { 'ret' : 0, 'count' : 0 }
req.OK = 1


print "Reached %d digests" % req.output['count']
When I try to run this program in standalone into my Pentium Dual Core
md4challenge reached 1.000.000 milion keys in 10 seconds but when i try
run this in embedded mode md5challenge reached about 200.000 more keys
!!! I
repeat this test many times and always wins embedded mode !!! What's
happen ?

Also I tested to erase read dependencies from /dev/random, and calculate
keys from same buffer. In this case embedded mode win always also, and
difference are more bigger !!!

Thks to all, can anybody help to me ?
So the above code corresponds to the standalone version - what about the
embedded version? Are you sure it is exactly the *same* code? All those
global statements are suspicious, and you don't even need most of them.
Note that looking up a name in the global namespace is much slower than
using a local name.
Also, you're including the time it takes the OS to *generate* several
megabytes of random data from /dev/urandom (how big is _const_b?).
Usually it's easier (and more accurate) to measure the time it takes to
compute a long task (let's say, how much time it takes to compute 1000000
md5 values). You're doing it backwards instead.
I'd rewrite the test as:

def try_me():
from md5 import md5
buff = os.urandom(_con st_b)
for i in xrange(1000000) :
md5(buff).hexdi gest()

def main(req):
t0 = time.clock()
t1 = time.clock()
# elapsed time = t1-t0
PS: Recuerdo que respondí esto en la lista de Python en castellano, pero
ahora veo que mi mensaje nunca llegó :(

Gabriel Genellina

Jun 27 '08 #1
0 1184

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

Similar topics

by: Paolo Losi | last post by:
Hi all, I'm pretty new to the python language so please excuse me if this is FAQ... I'm very glad to be part of the list! :-) I'm looking into a way to implement a generic workflow framework with python. The basic idea is to use python scripts as the way to specify workflow behavior. The framework should not only use scripts as a...
by: r.e.s. | last post by:
Should one expect the following execution times to be so different? ... Module_A takes about 4 seconds to run: x = (stuff_1) (stuff_2) Module_B takes about 80 seconds to run: x = (stuff_1) def f(y):
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain...
by: vishnu mahendra | last post by:
cah you please tell me how to find the execution time of a program in c. thank you in advance, vishnu
by: CptDondo | last post by:
I am working on an embedded platform which has a block of battery-backed RAM. I need to store various types of data in this block of memory - for example, bitmapped data for control registers, strings for logging, and structures for data points. I want to use one function to read data from this block and one function to write data, for...
by: Rich | last post by:
Hi, (this is a probably a bit OT here, but comp.lang seems rather desolated, so I'm not sure I would get an answer there. And right now I'm in the middle of learning Python anyway so...) Anyway, my question is: what experience you people have with working with different languages at the same time? Actually I did myself many years ago,...
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area....
by: Jack | last post by:
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to install? For Linux-based embedded systems in particular? I'm thinking of running it on the Linksys's Linux-based open source router WRT54G. It has 4MB flash and 16MB RAM. I think another model...
by: Uberman | last post by:
I have a bit of a odd arrangement here with SWIG, Python, Embedded Python and C++ classes exported into Python. Here's the plot: I have a class defined in a C++ DLL library. I am wrapping this class (we'll call it "Peter") with SWIG so some of its base functionality is available in Python. For the sake of this example, Peter has a method...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.