473,770 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird behavoir while using function aliases

I have the following script:

function Test(){}
Test.F = function(){}
Test.F.FF = function(){}
Test.F.FF.FFF = function(){}
Test.F.FF.FFF.F FFF = function(){}

//var alias = function(){};
var alias = Test.F.FF.FFF.F FFF;

var date1 = new Date();
for (var index = 0; index < 100000; index++)
Test.F.FF.FFF.F FFF();
//alias();
var date2 = new Date();
print(date2.get Time() - date1.getTime() );
Why is it when I use Test.F.FF.FFF.F FFF() I get around 100ms and when I
get alias() I get around 280ms?
What is going on here? This is something I would have never anticipated
and I think that neither of you as well. Aliases whould work faster
then doing lockups at each iteration, right?
Also if I uncomment this line: var alias = function(){}, from 280ms I
get a drop to 265 ms?

Does anybody now the reason for this? It only happends in Firefox (I
have 1.5.0.6). IE and Opera behaive as they should

Sep 19 '06 #1
22 2064
Daniel Rucareanu wrote:
<snip>
Why is it when I use Test.F.FF.FFF.F FFF() I get around 100ms and
when I get alias() I get around 280ms?
What is going on here? This is something I would have never
anticipated and I think that neither of you as well. Aliases whould
work faster then doing lockups at each iteration, right?
Also if I uncomment this line: var alias = function(){}, from 280ms I
get a drop to 265 ms?
Given the relatively low resolution and precision of javascript date
objects, and the influence of task switching on the processor, I would
not trust results from measurements of periods as short as this.
Does anybody now the reason for this? It only happends in Firefox (I
have 1.5.0.6). IE and Opera behaive as they should
If the effect is real, and particular to Firefox then asking the people
who wrote the javascript engine for Firefox may help. They:-

netscape.public .mozilla.jseng

Richard.

Sep 19 '06 #2
The precision of js date objects is indeed kind of low, but more the
enough when measuring durations larger than a few hundred milliseconds.

Also I don't think that tasks / threading switching have any influence,
because the result are constant, no matter how may time I run this
test. I also increased the loop from 100K iterations to 1M and the
results stay the same: using the alias is a lot slower.
Richard Cornford wrote:
Daniel Rucareanu wrote:
<snip>
Why is it when I use Test.F.FF.FFF.F FFF() I get around 100ms and
when I get alias() I get around 280ms?
What is going on here? This is something I would have never
anticipated and I think that neither of you as well. Aliases whould
work faster then doing lockups at each iteration, right?
Also if I uncomment this line: var alias = function(){}, from 280ms I
get a drop to 265 ms?

Given the relatively low resolution and precision of javascript date
objects, and the influence of task switching on the processor, I would
not trust results from measurements of periods as short as this.
Does anybody now the reason for this? It only happends in Firefox (I
have 1.5.0.6). IE and Opera behaive as they should

If the effect is real, and particular to Firefox then asking the people
who wrote the javascript engine for Firefox may help. They:-

netscape.public .mozilla.jseng

Richard.
Sep 19 '06 #3
Daniel Rucareanu wrote:
Why is it when I use Test.F.FF.FFF.F FFF() I get around 100ms and when
I get alias() I get around 280ms?
I get different results than you:
http://javascripttoolbox.com/temp/fu...peed_test.html

Using alias for me is always almost twice as fast in Firefox 2 beta 2,
10%-25% faster in FF 1.5, and 15%-20% faster in IE6.
Try my url and see if you get the same results.

In any case, doing a lookup 100,000 times and only taking 100-200ms total
surely makes these results insignificant.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 19 '06 #4
Strange enough, I get results close to you. Probably must have
something to do the fact the functions are passed as parameters... even
the total executions time, in both situations are smaller. Anyway, this
complicates thing even more, rather than answering them.
I have posted this on another forum as well and there people have
confirmed by results. You might want to try with my test as well, just
to see what kind of result you get.
In FF 2, beta 2, using my test, the alias() test runs 3 times more
slowly that the other test. Also, the fact the 100,000 iterations take
about 200ms is because the application is extremely simple. Rest assure
then in more complex applications with a lot of object, heavy dom usage
etc., the results will be different.

Thank you,
Daniel

Matt Kruse wrote:
Daniel Rucareanu wrote:
Why is it when I use Test.F.FF.FFF.F FFF() I get around 100ms and when
I get alias() I get around 280ms?

I get different results than you:
http://javascripttoolbox.com/temp/fu...peed_test.html

Using alias for me is always almost twice as fast in Firefox 2 beta 2,
10%-25% faster in FF 1.5, and 15%-20% faster in IE6.
Try my url and see if you get the same results.

In any case, doing a lookup 100,000 times and only taking 100-200ms total
surely makes these results insignificant.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 19 '06 #5
Daniel Rucareanu wrote:
<snip>
confirmed by results. You might want to try with my test as well, just
to see what kind of result you get.
<snip>

Firefox 1.5.0.6 gives me - alias() - running in about 3/4 of the time
that - Test.F.FF.FFF.F FFF() - takes, with your code. Your case is not
demonstrated.

Richard.

Sep 19 '06 #6
Richard Cornford wrote:
Firefox 1.5.0.6 gives me - alias() - running in about 3/4 of the time
that - Test.F.FF.FFF.F FFF() - takes, with your code. Your case is not
demonstrated.
Same here. Are you sure that your posted code is actually your complete test
case?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 19 '06 #7
Yes, the test case is complete. Hoever, for testing I was using an
online environment that evaluates whatever code you write. It suited me
fine until now when I needed just a quick way to test something. It
seems that is has something to do with it. Creating a standalone page
and running it does creates some more plausible results.
Strange that this is the first time the environments in giving me
results other then what a real page would give. If anybody want to run
the test there and to check the result, the url is:
http://www.squarefree.com/jsenv/.
In IE and Opera however, running the test in this environment or
running the standalone page gives the same results...
Now I wonder why 2 persons (whom I don't know) confirmed my first
results... :) What were they using?

Daniel
Matt Kruse wrote:
Richard Cornford wrote:
Firefox 1.5.0.6 gives me - alias() - running in about 3/4 of the time
that - Test.F.FF.FFF.F FFF() - takes, with your code. Your case is not
demonstrated.

Same here. Are you sure that your posted code is actually your complete test
case?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 19 '06 #8
Daniel Rucareanu wrote:
Yes, the test case is complete. Hoever, for testing I was using an
online environment ...
<snip>
http://www.squarefree.com/jsenv/.
<snip>

And that online environment branches its execution based upon a - !!
document.all - test, so no comparison of its results on different
browsers will be meaningful.

Richard.

Sep 19 '06 #9
Daniel Rucareanu wrote:
Yes, the test case is complete. Hoever, for testing I was using an
online environment that evaluates whatever code you write.
http://www.squarefree.com/jsenv/.
Ah, so you weren't just testing the speed of your test case, but also the
speed of any code wrapped around it to make the "environmen t" function.
These are important details not to be left out in the original post ;)

BTW, if you want to do speed tests, take a look at the code in the url I
posted in a previous message. I wrote the timeIt() function because I was
tired of manually doing the new Date() thing before and after, and I wanted
side-by-side comparisons of multiple ways of doing the same task. It's been
working nicely for me for a while.

One caveat: When testing long-running functions or many iterations, browsers
will usually pop up the "code is running slow" messages. Disable these in
your browser before doing speed tests.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 19 '06 #10

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

Similar topics

1
1975
by: Jim Dawson | last post by:
I was writing a subroutine to extract fields from lines of text when I ran into an issue. I have reproduced this error on Perl 5.8 on AIX, 5.8 on Linux and 5.6 on Windows. ############### CUT HERE ############### #!/usr/bin/perl -w my @list = ("field1 field2 field3"); sub stripws($)
2
4786
by: Johno | last post by:
I'm using the Dns class to query host names to check that they actually exist on our network and to determine the aliases for each host name. However, I've noticed that the IPHostEntry instance returned by Dns.GetHostByName doesn't return the host name's aliases in the IPHostEntry.Aliases list. But if I pass a host alias to GetHostByName it returns the alias in IPHostEntry.Aliases and the true host name in IPHostEntry.Hostname. It...
2
1441
by: Eyvind W Axelsen | last post by:
Hi. I am creating an application (primarily in C#), with MDI child windows. What I would like to do, is to override the default behavoir that makes a newly createad child form maximized if the topmost childform that already exists is also maximized. Furthermore, if I maximize one form, I don't want all the other forms to be maximized, and the same thing goes for 'restoring' forms to their original size. Any ideas?
24
4751
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
0
1640
by: Krzysiek | last post by:
Hi all, I have an issue with QSYS\QADBXREF file - it keeps aliases on tables. I take care of an application that works on many places (servers) and on one of them it's not possible to create alias. I've checked the authority of QADBXREF file on this 'problematic' machine and it's as follows: Object ----------Data--------- --------Object--------- User Group Authority Read Add Upd. Del. Exec. Opr Mgt Exist Alter Ref
15
2453
by: jacob navia | last post by:
Recently, we had a very heated thread about GC with the usual arguments (for, cons, etc) being exchanged. In one of those threads, we came into the realloc problem. What is the realloc problem? Well, it begins with a successfull realloc: char *q = realloc(p,2*n); // for n size_t, a simple
3
2800
by: AAJ | last post by:
Hi all I have the following that looks at a XSD Table adapter JobDescription.VWJobDescriptionMinEducationDataTable m_MinQuals; but for compactness I would like to reference it as Using JobDescription;
1
3185
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
7
2297
by: Joachim Schmitz | last post by:
Hi folks What would be the expected and correct output of the following #include <stdio.h> int main (void) { char buffer1 = "(10,20,30)"; char buffer2 = "(10,20,30 )"; /* add two white spaces between 30
0
9602
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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
10071
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...
0
9882
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
8905
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...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
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...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.