Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
Again: Running your JS in my browser console doesn't take 0.05secs (or
whatever), but more than 10secs. And you cannot have 200times more
capable hardware, that's for sure.
I'm not a 100% positive whether I still get the syntax right, but
move.d d0, 10000000;
djnz d0, label;
might be even faster - on a 68k-based system...
Anyway, since both PHP and various browsers and their JS implementations
are open source, you can just check how the loops are implemented.
(and java and C++) looks like this:
for (i = 0; i < 10000000; i++);
A for loop in PHP (and Perl) looks like this:
for ($i = 0; $i < 10000000; $i++);
A for loop in VBscript looks like this:
For i = 0 to 10000000 Next
How do you do a for loop in "My Porsche"? And if they're totally not
comparable then I'd be very interesting in knowing what those for
loops do on your system? Certainly they couldn't be doing the same
thing in those languages that they do in PHP because languages can't
possibly be compared!
Maybe the VBscript example actually prints out, on the screen, "hello
world!"? Certainly that'd make since given how totally fundamentally
different all languages are from one another!
I agree it is not very fast, but doing it the fast way would be like this:
and we wouldn't like to do that with a Porsche, would we?
Different languages sooner or later ends up in machine code when executed.
What you are comparing is which language is making the most efficient
machine code. The efficience could differ because some store their
variables in RAM, others in registers. There are also other ways to
optimize the code. One trivial optimization of your code would be to
simply replace your loop with:
i := 10000000;
as it would give exactly the same result as your code.
The fact that you can compare the time to cross a river with a boat and
the time to drive around a river with a Porsche does not mean that the
comparision is meaningful for any other purpose than crossing the river.
Your comparision with a loop doing nothing is meaningful for exactly
nothing. If you are considering to do a task and think about which
language to use you should compare the time it takes to do that task. You
should then loop over those caclulations, database accesses or whatever
your task requires instead of looping over nothing. With such a benchmark
you might find which language is fastest for your task, but still, that
benchmark would only apply to your specific task. Even with that knowledge
the performance of a language might not be the reason to choose that
The address in the header is only to prevent spam. My real address is:
hc3(at)poolhem.se Examples of addresses which go to spammers:
You're kidding. Of course these loops do the same on the level of the
used language, but how's the code executed internally? What steps are
taken in order to parse, prepare and run the code? That's where the
difference in running time come from.
Of course you can compare code and what it's supposed to do, but it's
hard to do any comparisons performance-wise, because there are way too
many variables in each environment.
As said in another post - try the same code in different PHP versions or
in different browsers: Even there you'll get different results because
of totally different PHP/JS engines.
I'm not denying that. Indeed, I already proposed something similar:
recognize that the for loop isn't doing anything and is just skipping
to the end". Or maybe it's doing something else. Presumably most of
the things it could be doing PHP could do, as well. Whether or not it
should is another matter entirely.
What I just find ludicrous is the whole "they're different and that's
all there is too it!" attitude. Why are they different? Oh, wait -
they're different because they're different! Wheee! What did the PHP
core development team do to make PHP5 faster than PHP4? I could
always say "I don't know what they did - here are the SVN repos for
both - maybe you can look and find out" but nah - I'll just say "My
Porsche is faster than PHP4 and you're a dense idiot of a troll for
If you genuinely want help, you might consider dropping the
The amount of research it would take to get any meaningful answer
isn't worth it. Do you expect someone to comb through the source
code from a half-dozen ECMAScript implementations (and at varying
versions), as well as various versions of PHP source code? But now
you have to consider the different systems on which the code would
be run, since the results of your benchmark aren't necessarily
governed by the implementations themselves.
I can understand why you'd be curious, but a far better approach
would be to learn more about language parsing and code generation.
I recommend purchasing _Compilers: Principles, Techniques, and
Tools_ (The Dragon Book). These topics, by themselves, are OT here.
What makes you think they necessarily changed for-loops in this
regard? That's just the point people have been making, the
differing results might be caused by a number of factors, even
outside PHP. However, expending the effort in trying to find out
why it's different yields no practical gain.
Okay, so you already had an idea about how to investigate. Since
you're the one who's curious, why don't you do your own research?
<? $x='<? $x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
No - I don't. To be honest, at the time I made my post, it didn't
occur to me to test on other browsers. I just sorta assumed that all
assumption as subsequent posts would demonstrate when they posted
their benchmarks and I can only hope that I won't make similarly dumb
assumptions in the future.
As for my subsequent posts... well, imho, this thread stopped being
discussion about benchmarks quite some time ago and more of a
"yawnmoth is stupid for even asking" thread and I don't agree with
that. Yes, my initial assumption was a bad one, but given that I
*did* have it, I don't see the question as being a bad one. Indeed,
as you observed, I can still pursue it and such pursuit wouldn't make
me an idiot. That it's not something you or anyone else would chose
to pursue does not mean it's a fundamentally flawed pursuit even
though that's the message I get from some of the posts that have been
made here. And people who do think that, imho, do deserve derision.
Also, when I made my PHP4 vs. PHP5 comment, I wasn't talking about for
loops. I was talking about in general. In general, PHP4 is faster
than PHP5. At least by some methods of benchmarking.
And as for the for loops in FF3.5 (for me) and in PHP5.3... if
to just random chance. Maybe Thunderbird was busy checking an SMTP
server during one of the trials or something. But that's not what the
difference was. It was 0.05 seconds vs. 2 seconds. And it was 0.05
seconds vs. 2 seconds consistently across multiple trials. That's not
chance. Another possibility (in addition to the one I proposed):
maybe the browser just operates with a higher priority than PHP does.
I'm willing to concede that maybe it has nothing to do with the
what else might it be? Although I don't care enough to devote much
time and effort to finding out it would be interesting to know. And
indeed, that's why I made my initial post.
I wasn't asking for people to spend hours and hours and hours digging
into Firefox's internals and PHP's - I was asking in case anyone knew
*of the top of their head*. And if it was (as I had idiotically
assumed) consistent across all browsers maybe it's something that
someone may have read about in a book or something. Maybe there was a
quick and easy explanation that I was simply unaware of. And now I
know that there isn't but what would you have proposed I do instead?
Not make dumb assumptions? Well, forgive me for saying so, but you
learn by doing. You learn *by* making dumb assumptions and being
called out on it, which I suppose is what happened. Mind you, people
could have just said "you're operating on bad assumptions" rather then
engaging in what amounts to name calling.
- The Natural Philosopher
January 25, 2010, 11:08 am
Yes, 'some'. Maybe. If at all. But without more details such comparisons
don't mean anything, as said earlier. PHP 5 got a completely new engine,
there's not much left over from PHP 4. Additionally some years ago a new
memory management was introduced, which also increased the performance.
Then there are new extensions to cache the bytecode and many more things
that didn't exist in PHP 4.
So even without any benchmarking I think it's safe to assume that PHP 5
is faster than 4, not the other way round.
January 25, 2010, 8:12 am
-----BEGIN PGP SIGNED MESSAGE-----
On 23/01/10 19:00, yawnmoth wrote:
Please don't stop.
My popcorn isn't empty yet, and I've enjoyed it so far !
Jesus, why can't ppl needs to discuss stuff they can't change ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
-----END PGP SIGNATURE-----
- Captain Paralytic
January 25, 2010, 12:30 pm
I wonder why no one has responded with anything as flippant as "My PHP
program is heavier than water!"...
- Captain Paralytic
January 25, 2010, 11:14 pm
- Captain Paralytic
January 26, 2010, 11:42 am
Mark Smith schreef:
Reminds me of a fun story of that great, now gone, Richard Feynman.
When studying physics the teacher decided to tease the class, filled
with freshmen, a little with a (famous) trickquestion:
"What weights more: A kilogram of iron or a kilogram of feathers?"
The smarter students smiled and answered: "They weight the same, since
you say they both have a mass of 1 kilogram."
The teacher was of course happy and wanted to continue his lesson.
Then Feynman said: "Well, it is not that simple. If I put a kilogram of
feathers on a balance it will show less weight than for a kilogram of
The teacher smiled knowingly, and started to explain it to that slow
But Feynman was right. :-)
Feynman: "Look, A kilogram is a kilogram, no discussion there, so they
have the same mass. But you all seem to forget that a kilogram of
feathers displaces more air because it occupies a greater volume, so it
experiences more upward presure, like a baloon held under water. Iron
displaces much less volume. So the kilogram of iron weights more. If you
put them both on an accurate balance you will see that a kilogram of
feather weights slightly less."
I wonder how that teacher reacted. :-)
As with many stories about Feynman, you can never be sure if it
Did I stray off-topic here? ;-)
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
On Tue, 26 Jan 2010 16:32:33 +0100, Erwin Moller wrote:
I'd hope it didn't, because it's wrong. It would be correct if the space
in the volume of feathers was filled with helium. But the balloon needs
to be held under water because it's filled with air, not water.
83. If I'm eating dinner with the hero, put poison in his goblet, then
have to leave the table for any reason, I will order new drinks for
both of us instead of trying to decide whether or not to switch
with him. --Peter Anspach's list of things to do as an Evil Overlord