You are not logged in.

#1 2008-06-01 18:33:13

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

(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 smile

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

#2 2008-06-01 18:48:22

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

Did you use different compile flags under PCLOS?

Offline

#3 2008-06-01 18:51:11

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#4 2008-06-01 18:55:25

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

Um....how did you compile the program? Did you write a PKGBUILD and a spec file for each distro?

Offline

#5 2008-06-01 18:56:35

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

well, i just do the simple

$g++ main.cpp

Does 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

#6 2008-06-01 18:59:01

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

I can do it in 6secs tongue

[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 2008

CFLAGS="-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


Website - Blog - arch-home
Arch User since March 2005

Offline

#7 2008-06-01 19:00:39

Asgaroth
Member
From: Hesse, Germany
Registered: 2008-03-26
Posts: 58

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#8 2008-06-01 19:09:24

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

OK, im sorry for providing some irrelevant details big_smile

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

#9 2008-06-01 19:20:02

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

I doubt it has anything to do with your hard drive, its only a 8KB file

8.0K    test

Website - Blog - arch-home
Arch User since March 2005

Offline

#10 2008-06-01 19:51:12

Kknd
Member
From: Brazil, Santa Catarina
Registered: 2007-08-15
Posts: 98
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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 2008

Last edited by Kknd (2008-06-01 19:51:42)

Offline

#11 2008-06-01 21:22:15

Jessehk
Member
From: Toronto, Ontario, Canada
Registered: 2007-01-16
Posts: 152

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#12 2008-06-01 21:50:23

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 3,528

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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 total

Edit:
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

#13 2008-06-01 22:25:31

Barrucadu
Member
From: Hull, England
Registered: 2008-03-30
Posts: 1,157
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

It took me 10s to run that, but I do have an old machine.

Offline

#14 2008-06-02 02:09:10

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#15 2008-06-02 02:11:41

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#16 2008-06-02 02:35:30

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 9,939
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#17 2008-06-02 02:57:06

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

What would file systems have to do with anything, especially with an 8kb program?

Last edited by pyther (2008-06-02 02:57:23)


Website - Blog - arch-home
Arch User since March 2005

Offline

#18 2008-06-02 03:00:05

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 9,939
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

I agree, I am just trying to rule it out completely.  Something appears to be going on...

Offline

#19 2008-06-02 04:00:34

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#20 2008-06-02 04:38:41

B-Con
Member
From: Frisco, TX
Registered: 2007-12-17
Posts: 549
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#21 2008-06-02 04:41:46

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 9,939
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#22 2008-06-02 05:12:00

Mr_Shameless
Member
Registered: 2008-05-20
Posts: 19

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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.img

Does 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

#23 2008-06-02 05:21:17

B-Con
Member
From: Frisco, TX
Registered: 2007-12-17
Posts: 549
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

#24 2008-06-02 07:21:31

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 960
Website

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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.out

Run that on both platforms. My Core Duo 1.6 laptop:

real    0m9.868s
user    0m9.753s
sys     0m0.043s

i586 has no effect, just +- 2 to 300ms at most. But i686 does:

real    0m6.302s
user    0m6.263s
sys     0m0.023s

But 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

#25 2008-06-02 07:47:16

jealma
Member
From: The Netherlands
Registered: 2008-01-03
Posts: 71

Re: C++ program, Arch took 14 secs while PCLOS, Ubuntu, Mandriva only 8-9.

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

Board footer

Powered by FluxBB