Ubuntu Disappointing Performance for Computing Load

I found a rather poor performance by executing some computing code under Ubuntu on a completely new headless workstation machine, which I use for scientific computing. I noticed a difference in the execution speed of a bit complicated code on Ubuntu compared to my old Mac laptop, which I use for development. However, I managed to translate it into an incredibly simple example, which still shows less than an improvement in the stelar over my old machine:

#include <stdio.h> #include <math.h> int main() { double res = 0.0; for(int i=1; i<200000000; i++) { res += exp((double) 100.0/i); } printf("%lf", res); return(0); } 

Now the Mac is an almost 5-year-old 2.4-GHz Core 2 Duo MacBook Pro running on OS X 10.5 that runs this code in about 6.8 seconds. However, it takes about 6.1 seconds on a brand new Dell 3.7-GHz Core i7 processor running Ubuntu 11.10! Can someone enlighten me about what is happening here, because it is absurd that an almost 5-year-old laptop is within 10% of the new desktop workstation? This is even more absurd, because I see that the Core i7 is turbocharged up to almost 4 GHz with monitoring tools!

Mac compiled with

 gcc -o test test.c -std=gnu99 -arch x86_64 -O2 

Ubuntu compiled with:

 gcc -o test test.c -std=gnu99 -m64 -O2 -lm 

Thanks,

Louis

+6
source share
6 answers

it is absurd that an almost 5-year-old laptop is within 10% of the new desktop workstation

Remember that you are comparing one specific function ( exp ). We really do not know if the two implementations of the exp() function that you are comparing are identical (it is possible that one is better optimized than the other).

If you want to compare another function, the results can be completely different (maybe more according to your expectations or not).

If exp() really the bottleneck of your actual application, you might consider using a quick approximation. Here is a document that offers one such approximation: Fast, compact approximation of an exponential function .

+3
source

As others have noted, you are simply comparing the implementation of one math library exp( ) with another. If you need high-quality math libraries on Linux, I would suggest looking at the Intel compiler tools (which come with an excellent set of libraries); they are also available for OS X and Windows.

+1
source

Try turning on the -ffast-math option. This may give you a less efficient pedantic implementation of exp() . The question then becomes: do you want a potentially incorrect answer that may arise.

+1
source

You compare apples and oranges, for Mac you enable architecture-specific optimizations that you don't use for ubuntu. Use -O3 -march=native in order to have a fair comparison.

0
source

A few things to try:

  • Make sure that during the experiment, your processor is configured to constantly work at full speed. It can switch up and down, which adds a lot of overhead
  • Connect the test program to one core using taskset so that the OS scheduler does not transfer it
0
source

the difference in the number of cpu cycles is only 30%. Given that we do not know exactly what code the compiler generated, I would not say that this is absurd. Most of the performance with your new processor is the number of cores, and your code does not use this.

It may also be interesting to try and deploy a loop. Speed ​​factor may change.

 int main() { double res0 = 0.0; double res1 = 0.0; double res2 = 0.0; double res3 = 0.0; double res4 = 0.0; for(int i=1; i<200000000; i+=5) { res0 += exp((double) 100.0/i); res1 += exp((double) 100.0/(i+1)); res2 += exp((double) 100.0/(i+2)); res3 += exp((double) 100.0/(i+3)); res4 += exp((double) 100.0/(i+4)); } double res=res0+res1+res2+res3+res4; printf("%lf", res); return(0); } 
0
source

Source: https://habr.com/ru/post/909203/


All Articles