473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bizarre additional calling overhead.

>>def test_func():
.... pass
....
>>import new
test_func2 = new.function(te st_func.func_co de, {}, "test_func2 ")
test_func2
<function test_func2 at 0x01B8C2F0>
>>test_func
<function test_func at 0x01B8C270>
>>import timeit
tf = timeit.Timer("t est_func()", "from __main__ import test_func")
tf.repeat()
[0.2183461704377 247, 0.1806821531448 9791, 0.1797858584149 8085]
>>tf2 = timeit.Timer("t est_func2()", "from __main__ import test_func2")
tf2.repeat( )
[0.4001539023989 0891, 0.3589345287939 6648, 0.3603462813373 7456]
>>>
Why almost twice the calling overhead for a dynamic function?
Nov 2 '07 #1
2 1120
On Nov 2, 3:08 pm, "Chris Mellon" <arka...@gmail. comwrote:
>def test_func():

... pass
...>>import new
>test_func2 = new.function(te st_func.func_co de, {}, "test_func2 ")
test_func2

<function test_func2 at 0x01B8C2F0>>>te st_func

<function test_func at 0x01B8C270>>>im port timeit
>tf = timeit.Timer("t est_func()", "from __main__ import test_func")
tf.repeat()

[0.2183461704377 247, 0.1806821531448 9791, 0.1797858584149 8085]>>tf2 = timeit.Timer("t est_func2()", "from __main__ import test_func2")
>tf2.repeat()

[0.4001539023989 0891, 0.3589345287939 6648, 0.3603462813373 7456]

Why almost twice the calling overhead for a dynamic function?
So, I don't have an official explanation for why it takes twice as
long, but the only difference between the two functions I could find
was that test_func.func_ globals was set to globals() and
test_func2.func _globals was an empty dict. When I re-created
test_func2 with globals set to globals() it ran just as fast as
test_func.
>>test_func2 = new.function(te st_func.func_co de, globals(), "test_func" )
tf2 = timeit.Timer("t est_func2()", "from __main__ import test_func2")
tf2.repeat( )
[0.1811911849131 3202, 0.1839622074871 8406, 0.1872240745681 2107]
>>tf.repeat()
[0.1812512484129 9112, 0.1798125180714 5782, 0.1851799600228 7873]

Matt

Nov 3 '07 #2
On Fri, 02 Nov 2007 17:08:06 -0500, Chris Mellon wrote:
>>>def test_func():
... pass
...
>>>import new
test_func2 = new.function(te st_func.func_co de, {}, "test_func2 ")
[snip results of timeit]
Why almost twice the calling overhead for a dynamic function?
When I time the functions, I get a lot of variability. The minimum value
is probably the best one to look at:
>>min(timeit.Ti mer("test_func( )",
.... "from __main__ import test_func").rep eat(20))
0.3566401004791 2598
>>min(timeit.Ti mer("test_func2 ()",
.... "from __main__ import test_func2").re peat(20))
0.6813821792602 5391
Disassembling the code does not give any hints:
>>import dis
dis.dis(test_ func)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
>>dis.dis(test_ func2)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE

Which is what we should expect, because both functions have the same code:
>>test_func.fun c_code is test_func2.func _code
True
But try this:
>>test_func3 = new.function(te st_func.func_co de,
.... globals(), 'test_func3')
>>min(timeit.Ti mer("test_func3 ()",
.... "from __main__ import test_func3").re peat(20))
0.3577220439910 8887
Hmmm... it looks like the difference in speed has to do with the globals,
not the fact that it is created dynamically. I wonder why?


--
Steven.
Nov 3 '07 #3

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

Similar topics

4
2171
by: Alan Little | last post by:
This is very bizarre. Could someone else have a look at this? Maybe you can see something I'm overlooking. Go here: http://www.newsletters.forbes.com/enews/admin/deliver.php4 U: bugtest P: test Enter 1 for "How many files in this delivery?" and select a file to upload, in one of the listed formats. Scroll down and click "Test Email".
1
6741
by: Lakshmi | last post by:
Hi All, I am having performance issues with the .NET client calling the Java Webservice running on axis. Have detailed the problem below. Please help. I wrote a webservice in Java. Lets name this WebService1. (using Apache Axis 1.1) Scenario 1: -----------
11
3454
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the vtable pointer is made use of.. eg. class one {
4
3212
by: dave m | last post by:
I'm creating a class library (dll) and am confused as how to pass any information, should any exceptions occur, back to the calling application. Such as: Try x = 3 / 0 ' divide by 0 error Catch ex as Exception '(how do I pass ex info back to calling app?) End Try
6
1985
by: Anthony Smith | last post by:
I can call a class using "->", but it complains about the :: I see on the net where :: is used. Is there a good explanation on when to use one over the other or the differences? $help = new help(); $help->foo(); $help::foo(); class help{
3
5270
by: Beorne | last post by:
I have a propertary library dll (used to drive a device) that I call from my C# code. Calling the functions from C++ is really faster than calling them in C+ +. From C++ the call is almost instantaneous, from C# is about 1.5 seconds long. For example, this command powers a device based on an interface switch and returns a message in Ack_Msg that is len long. Besides returns an error code.
35
2253
by: bukzor | last post by:
I've found some bizzare behavior when using mutable values (lists, dicts, etc) as the default argument of a function. I want to get the community's feedback on this. It's easiest to explain with code. This example is trivial and has design issues, but it demonstrates a problem I've seen in production systems: def main(argv = ): 'print out arguments with BEGIN and END' argv.insert(1, "BEGIN")
2
1327
by: Tom | last post by:
My older system: Win2k, VS2005(Academic), .Net 2.0 SP1. Windows.Forms Application: Two splitter panels, a TreeView (named: "tree") in one panel populated with directory name nodes. Logic for programmatically selecting a previously saved FullPath is being called from the tree.Enter() event handler; After expanding to a specific folder and selecting it (for testing purposes I chose a specific folder that is level 4 depth) ... I
20
1279
by: Jasper | last post by:
I'm stumped. I'm calling a method that has keyword args, but not setting them, and yet one of them starts off with data?! The class definition begins like so: class BattleIntentionAction( BattleAction ): def __init__( self, factionName, location, tactic='hold', targetFacName='', terrainArgs=, garrisonIds= ): self.terrainArgs = terrainArgs print terrainArgs
0
9498
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.