OS X vs. Linux (x86) speed?

bbloke

Registered
A friend of mine who is very experienced with Linux and various forms of UNIX asked me to run a speed test via the Terminal app. He said that his laptop (running Linux) executed the following command in 48 seconds:

time awk 'BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}'

On my QuickSilver DP 1 GHz machine, it took... 60 seconds! I asked how fast his laptop was and was disappointed to find it was only a 1.13 GHz (Pentium) machine. :eek:

I'm not out to start any G4 vs. Pentium debates, but I wondered why his laptop would astonish me by performing so very much better than I expected compared to my G4! It also is particularly odd, as it does not reflect my "feeling" of the relative speeds in the real world (I use a 1.5 GHz P4 at work, alas). A different friend of mine ran some C-based code on his Linux machine (600 MHz x86) and surprised himself by finding it was quicker than when compiled on what was supposed to be a much faster UNIX workstation.

I'm not a programmer, and I'm not an expert on hardware or coding. But I have been left wondering what the reasons could be. Does Linux have any particular advantage in this area? Does this test bring out the particular strengths/weaknesses of the different architecture?
 
Too many things too explain... Move along there is nothing to understand here other than give us another reason to flame each other... :p

Still, you may want to know that Linux for Mac exists and in many distributions too! :D
 
:eek:

Erm, this was definitely not an attempt to start a flame war! I'm genuinely interested to get to the bottom of this, as the results really surprised me and I wondered if any UNIX/Linux users here would know of any particular biases in the test.

I am well aware that Linux exists in different incarnations for the Mac, too. :rolleyes:

Honestly, this is not about starting an argument, I'm genuinely after information! :(
 
hmm dual processors don't help u much here I'd say. And linux is prolly a bit faster than os x too

1min 31s on 700mhz G4 iMac
(safari, iTunes, finder, X-Chat aqua, konfabulator running in bg)

1min 42s on 600mhz celeron / redhat9
(mldonkey, BitchX in bg, no window server, console only & me ssh-ing in)
 
It's quite simple actually:

FPU = floating point unit (FP math operations)

ALU = err... Arithmatic L-something Unit. So it's integer math.

Pentium: Strong ALU, weak FPU.

G4: String FPU, weak ALU.

Software optimized for Pentium processors have to use SSE/SSE2 instructions for floating point math to increase performance.

And if you look at OSX developer docs, especially the API reference, Apple designed the Cocoa framework to use the FPU for even simple arithmatic, by way of using floating point data types when regular integers would be sufficient.

The code your friend asked you to run simply iterates an variable (i) from 0 to 10,000. But it does not explicitly say what data type 'i' is, so it probably defaults to int (integer). Not only does your friend's laptop have more MHz on you, but it also has stronger integer performance.

If you were to redo the test but find a way to ensure the data type used is floating point and not integer, the results may be better in the G4's favor.
 
Another important thing is that awk is a dinky little scripting language for processing text files. The program you entered was not compiled but instead it was interpreted by the awk interpreter. Under Linux awk is gawk (the GNU reimplementation), and on OSX it is the original awk.

So what you are really doing is comparing the performance of to totally unrelated implementations of interpreters for the awk language running on totally different machines and OSes. As a general rule GNU stuff is faster as they have been able to learn from the mistakes of their predecessors, so with everything being equal gawk should be faster.

I hope it is clear that this really is an appels vs. oranges kind of comparison...
 
And I will repeat:
"Too many things too explain... Move along..."

Flame thread or not! :D

If ANYONE believes seriously that a G3/G4 CPU is slower than a Wintel/Amd running @ same MHz by using the above method, hmmmmm :rolleyes:
 
Well the above method doesn't prove anything hardware-wise but it does prove that OSX could have used better open-source tools. Scripting/interpreted environments are obviously slower than native byte code but it does illustrate weaker integer math of the PPC platform, inspite of having better branch prediction.
 
Originally posted by Lycander
Well the above method doesn't prove anything hardware-wise but it does prove that OSX could have used better open-source tools. Scripting/interpreted environments are obviously slower than native byte code but it does illustrate weaker integer math of the PPC platform, inspite of having better branch prediction.

Actually it doesn't say anything about OSX not having better opensource tools. gawk is actually slower then the original awk (1977 specs), as well as the newer awk (1985 specs).

This was done on my Sun Ultra60 with 2x450Mhz processors.
Code:
$ for x in awk nawk gawk; do
> echo "doing $x"
> time $x 'BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}' < /tmp/awkawk
> done
doing awk

real     2:00.1
user     1:49.2
sys         0.0
doing nawk

real     1:55.6
user     1:45.2
sys         0.0
doing gawk

real     2:04.2
user     1:53.7
sys         0.0

awk uses 109secs of actual cpu, nawk uses 105secs of cpu, while gawk uses 113secs. On solaris awk is by default the 1977 spec awk, nawk is the 1985 spec awk, which is what most other systems list as awk. The redirection of /tmp/awkawk is just an empty file and is needed as the original awk expects some sort of input.

As to the original question, alot of things can cause differences. Many of them have already been mentioned, but there are others such as some x86/linux only optimizations which can be done with gawk to increase performance, there may be different optimization levels used in the compile of the software, etc. A much better test would be something that actaully taxes the system,and does a wide range of things, instead of just a for loop. A good test might be the mysql benchmark test that tests a wide range of things. It's located in the sql-bench directory or a standard mysql install.

Brian
 
Originally posted by btoneill
Actually it doesn't say anything about OSX not having better opensource tools. gawk is actually slower then the original awk (1977 specs), as well as the newer awk (1985 specs).
Someone above had said gawk was faster than awk, so I was going with that lead. I don't know myself I've never used (g)awk.
 
use C compile it natively and test test test test test

then use int and doubles and test test test test test

then use the interpreters but forget testing it.
 
Originally posted by Lycander
Someone above had said gawk was faster than awk, so I was going with that lead. I don't know myself I've never used (g)awk.

Don't put much creedence into my random spouting off in the presence of real data :) I also did not say that it was faster just that it most likely was faster. When you look across the set of GNU vs Unix tools as a general rule the GNU stuff is faster for the reasons I cited. But that is only in general any specific instance may go the other direction.

One thing that both the Sparc and the PPC have in common is that they do not natively do byte level addressing which the x86 does do. So applications which munge character strings like awk may actually have a little advantage on x86 because the other processors have to do some funky magic to work with 8 bit data.

Take that last point with a grain of salt though because my old Apple ][ also had byte level addressing.

-Eric
 
There shouldn't be a difference, it just goes by your processor speed. (Not "just," but there's little if any interference caused by overhead like Aqua.)
 
side note... pop open your CPU monitor... notice only one of the processors is being used. My dualie 1ghz ran it in 48 seconds with itunes, safari, photoshop, dreamweaver, and ichat open. No point being made at all.
 
oh boy. That test is sooooooo not about OSes. It's loosely about hardware performance on a type of manipulation that doesn't do any work. It's the type of operation which is helped by MHz and MHz alone, the fatness and FPU coolness of the PPC does nothing here. Java interpretation suffers a similar fate though, so it's probably roughly indicative of how fast an interpreter could be run on those hardware platforms.

Since it's a loop, it's probably not a good test of OS, memory allocation, stability, or actually getting work done. At least he didn't try printing 10,000 asterisks and use that data to claim that OS X was slow.

A lot of research could be done on how to benchmark a system, and this would be a classic demo of how to make a nearly worthless benchmark. It's probably fairly closely related to SPEC-int for the processors it's running on, which is also a nearly worthless benchmark for a whole computer, but is useful for predicting how fast a CPU will munge through a loop without doing any work. :) How do you like that circular logic?
 
Back
Top