You are not logged in.
(At the beginning, the title of this thread was "Arch took 14 secs while PCLOS only 9", but I later found out that all the other distros that i tried also executed it just as fast. Hence, I changed the title a bit, just to avoid misleading.)
Hi everybody.
I just installed Archlinux again, after a few weeks playing with PCLinuxOS.
I have to say that PCLinuxOS was faster than I expected, seeing its comprehensiveness.
But one thing made me surprised, it executed my program faster than Archlinux. I think it is me doing something wrong here, and I need your help.
This is the source code of my small program, as a brute-force method to solve a math problem:
#include <iostream>
#include <cstdlib>
using namespace std;
const unsigned char SIZE = 15;
unsigned long long result;
void count(unsigned char i, unsigned char j)
{
if(!i && !j) {
++result;
return;
}
if(i) {
count(i - 1, j);
}
if(j) {
count(i, j - 1);
}
}
int main()
{
system("date");
result = 0;
count(SIZE, SIZE);
cout << result << endl;
system("date");
return 0;
}When I compiled and ran it under PCLinuxOS 2008, it took around 8-9 seconds to give me the result. Under Arch, it always took 14 seconds to complete.
This is a Core 2 Duo T5500, 2 gigs of RAM.
Here are my CFLAGS in /etc/makepkg.conf, though i don't think it affects small programs like this:
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"Please help me figure out where the problem may lie in. Thank you very much ![]()
PS: I did had a look cat cpu frequency when the program was running in Arch. It already ran at max speed.
Last edited by Mr_Shameless (2008-06-02 05:36:10)
Offline
Did you use different compile flags under PCLOS?
Offline
No. Under PCLOS, im not sure what the compile flags were, but I left them as is. I guess they were i586 as the other packages.
Offline
Um....how did you compile the program? Did you write a PKGBUILD and a spec file for each distro?
Offline
well, i just do the simple
$g++ main.cppDoes the /etc/makepkg.conf file afftect that, anyway?
I will try running this on some other LiveCDs. (For PCLOS, it was installed on my computer)
Last edited by Mr_Shameless (2008-06-01 18:58:16)
Offline
I can do it in 6secs ![]()
[pyther@tux ~]$ time ./test
Sun Jun 1 14:54:47 EDT 2008
155117520
Sun Jun 1 14:54:53 EDT 2008
real 0m6.595s
user 0m6.540s
sys 0m0.004s
[pyther@tux ~]$ ./test
Sun Jun 1 14:55:08 EDT 2008
155117520
Sun Jun 1 14:55:14 EDT 2008CFLAGS="-march=athlon -O2 -pipe -fomit-frame-pointer -msse3"
compile command="g++ test.cpp -o test"
Specs:
-AMD X2 3800
-3GB Ram
Things to note: I recompiled nearly my whole system (with my cflags) and I have a custom kernel
Offline
How did you compile it? Just by typing "g++ -o foo foo.cpp"? If so, the compiler flags set in makepkg.conf and the pclos equivalent are irrelevant, since they are just used for building packages.
Normally a distribution should not matter in such computation tasks, so the two most probable reasons i can think of are different compiler flags and stuff running in the background thus stealing cpu time. So just compile them using the same flags and make use you have roughly the same amount of applications/cpu usage running in the background. (Well compiler flags used for building used libraries would also matter, but here, there are no libs used in the time-consuming part.
OffTopic: Runs in 2 seconds on my machine(Core 2 Duo 2,0 GHz, g++ -march=prescott -O3 -fomit-frame-pointer ..).
Last edited by Asgaroth (2008-06-01 19:05:49)
Offline
OK, im sorry for providing some irrelevant details ![]()
Under PCLOS and Arch, this program was run when there was no other active programs running, and tested many times.
I mainly use KDE, but i also tried fluxbox under PCLOS, and icewm in Arch here, the result is the same.
PS: i haven't done anything related to hdparm stuff. Could it be the hard drive? But the program should lie in RAM already after many times, right?
Last edited by Mr_Shameless (2008-06-01 19:12:08)
Offline
Like Asgaroth says, you must export your CXXFLAGS before execution, or compile with
g++ -O2 -fomit-frame-pointer -march=core2 and etc by hand.
Here is my test:
[kknd@TuxDev Desktop]$ g++ -O2 -Wall -fomit-frame-pointer -march=core2 test.cpp -o test
[kknd@TuxDev Desktop]$ time ./test
Dom Jun 1 16:49:01 BRT 2008
155117520
Dom Jun 1 16:49:07 BRT 2008
[kknd@TuxDev Desktop]$ g++ test.cpp -o test
[kknd@TuxDev Desktop]$ time ./test
Dom Jun 1 16:49:28 BRT 2008
155117520
Dom Jun 1 16:49:35 BRT 2008Last edited by Kknd (2008-06-01 19:51:42)
Offline
I'll just reiterate that the CFLAGS in /etc/makepkg.conf are only applied when using makepkg or another similar tool.
You have to supply the flags to gcc/g++ manually when you're compiling programs like that.
Offline
Here are my results:
[oh@Alice][~/test/a]%g++ test.cpp -o test
[oh@Alice][~/test/a]%time ./test
Sun Jun 1 23:46:43 CEST 2008
155117520
Sun Jun 1 23:46:48 CEST 2008
./test 5.23s user 0.01s system 98% cpu 5.341 total
[oh@Alice][~/test/a]%g++ -march=core2 -mfpmath=sse -O2 -pipe -fomit-frame-pointer test.cpp -o test2
[oh@Alice][~/test/a]%time ./test2
Sun Jun 1 23:48:30 CEST 2008
155117520
Sun Jun 1 23:48:34 CEST 2008
./test2 3.75s user 0.00s system 99% cpu 3.786 totalEdit:
E6550 @ 2.8GHz (7x400)
Last edited by Mr.Elendig (2008-06-01 22:52:28)
Evil #archlinux@freenode channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
It took me 10s to run that, but I do have an old machine.
Offline
I have just tried under Ubuntu 8.04 and Mandriva 2008. The binary was compiled in Ubuntu. It took 8-9 seconds under both of them.
Then I tried that same binary under my working Arch system, as well as the install CDs, 2008.03 and 2007.08. Arch consistently took 14 seconds.
It made no difference whether X is running or not.
This is the same binary compiled under Ubuntu, so it is not the version of GCC or any CFLAGS settings, hmmm.....
I wish i could find where the problem is from.
Offline
Hey, could it be the timer frequency in the kernel settings? Arch defaults to 300MHz right? Could the be this setting that made the system print out time later than on the other systems?
But that can't be like 5-6 seconds, right?
Offline
Do your filesystem types match? There are some speed advantages depending on where on the hard-drive your file is but nothing in that order.
Offline
Offline
I agree, I am just trying to rule it out completely. Something appears to be going on...
Offline
I tried recompiling the kernel, with specific options for my CPU, and Timer to 1000MHz but that didn't help. Same result, 14 seconds. How weird...
Offline
Do Arch and PCLinuxOS use different Kernel patches? As I recall, there exist different kernel patches for different process schedulers, perhaps Arch and PCLOS use different ones and your program falls into the realm of PCLOS's strength.
- "Cryptographically secure linear feedback based shift registers" -- a phrase that'll get any party started.
- My AUR packages.
- I use i3 on my i7.
Offline
Well, that could definitely be it. Arch uses the latest kernel with the new scheduler which hasn't been fully optimized yet. What kernel are all the others using?
Offline
Hmm.... I guess you are right.
I'm not sure, but I downloaded the kernel from here: ftp://ftp.us.kernel.org/pub/linux/kerne … 25.tar.bz2. That is vanilla, isn't that? Because both kernels, the one provided by Arch and the one I compiled myself resulted in the same thing.
I just downloaded the source, then:
$zcat /proc/config.gz > .config
$make oldconfig
$make menuconfig
$make
#make modules_install
#mkinitcpio -k 2.6.25-CUSTOM0 -g /boot/kernel26-CUSTOM0.imgDoes that apply any patches to the kernel? I've never applied any patch to the kernel myself, so I have no idea how that works.
Offline
Compiling the raw kernel includes not patches -- patches by definition alter the vanilla kernel.
Likely if any extensive differences exist between the two kernels, they are patches in PCLOS, as Arch stays pretty vanilla. From a glance through the PKGBUILD for kernel26, it looks like there's only one major patch applied.
- "Cryptographically secure linear feedback based shift registers" -- a phrase that'll get any party started.
- My AUR packages.
- I use i3 on my i7.
Offline
We're missing the point here. We shouldn't be talking about optimising the compiler flags on one system and leave the other as it is. Benchmarking means falling to as much a "default" state as possible for all the variables concerned. I'm not sure whether Ubuntu or those other distribs export CFLAGS traditionally, but I presume not. As such, we should also not be dwelling on further optimisation on just one system, but rather we should carry out the tests in parallel.
g++ -march=i386 -O2 -pipe file.cpp
./a.outRun that on both platforms. My Core Duo 1.6 laptop:
real 0m9.868s
user 0m9.753s
sys 0m0.043si586 has no effect, just +- 2 to 300ms at most. But i686 does:
real 0m6.302s
user 0m6.263s
sys 0m0.023sBut this won't explain why in the default state Arch is slower. By default, you aren't running with any flag set on both the Arch and {Ubuntu,PCLinuxOS,DistroXXX}. So on the same hardware, we'd expect similar results. The culprit is most likely kernel-level, since we know pre-packaged distros normally do a lot of "perfromance" patching. Arch applies patches which are deemed to be important, so random performance patches are out of the question. But if someone can convince us of a patch that deals with this particular issue, it may get in. Btw, look at the linked git repo in the PKGBUILD. I don't where to see the list of patches without looking at the combined patch itself.
Thanks for reminding me of another issue - my machine. Normally it's recommended to use prescott as the arch together with -mfpmath=sse for Core Duo, but I see now that this is as slow i386 as far as this set of hardware is concerned. I would've gotten much better speed from using i686, and now thanks to the new gcc, -march=native. Anyway, remember to export/include CFLAGS, or at least source /etc/makepkg.conf before compiling C/C++ code.
Last edited by schivmeister (2008-06-02 07:23:51)
I need real, proper pen and paper for this.
Offline
Hmm, just a little over 4 seconds on a C2D E6400 @ 3GHz, with Arch64 and stock kernel 2.6.25.4-1
Mon Jun 2 09:47:02 CEST 2008
155117520
Mon Jun 2 09:47:06 CEST 2008
real 0m4.675s
user 0m4.650s
sys 0m0.010s
Last edited by jealma (2008-06-02 07:48:51)
Offline