I seem to have a disguised gcc/clang thing...

gcc --version

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr
--with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Installing gcc from homebrew gives the same result:

/usr/local/Cellar/gcc/7.1.0/bin/gcc-7  -O2 main.c -o ccode-gcc-brew -lm
➜  c time ./ccode-gcc-brew
sum=606329794183272.375000
./ccode-gcc-brew  4.01s user 0.01s system 99% cpu 4.037 total



fre 4 aug. 2017 kl 10:15 skrev <pedr...@cpmech.com>:

> wait, what?!
>
> the same code:
>
> #include "stdio.h"
> #include "math.h"
> int main() {
>     double res = 0.0;
>     double x = 2.5;
>     int Nmax = 10000000;
>     for (int N=0; N<Nmax; N++) {
>         for (int i=0; i<20; i++) {
>             res += pow(x, i);
>         }
>     }
>     printf("res = %g\n", res);
> }
>
> compiled with Clang is much faster?
>
> yes, I get:
>
> gcc -O2 c-code-sum.c -o c-code-sum_GCC -lm
> time ./c-code-sum_GCC
> res = 6.0633e+14
>
> real 0m8.210s
> user 0m8.208s
> sys 0m0.000s
>
> and:
>
> clang -O2 c-code-sum.c -o c-code-sum_CLANG -lm
> time ./c-code-sum_CLANG
> res = 6.0633e+14
>
> real 0m0.157s
> user 0m0.156s
> sys 0m0.004s
>
> So the question might be: what is CLANG doing? (and how to do this with
> Go?...)
>
>
> On Friday, August 4, 2017 at 6:04:01 PM UTC+10, Sebastien Binet wrote:
>
>>
>>
>> On Fri, Aug 4, 2017 at 9:51 AM, Henrik Johansson <dahan...@gmail.com>
>> wrote:
>>
>>> Actually I get the same as the original program on my mac.
>>>
>>> time ./ccode
>>> sum=606329794183272.375000
>>> ./ccode  0.17s user 0.00s system 98% cpu 0.170 total
>>>
>>> The Go version -O2 -Wall
>>> time ./pow
>>> sum=6.063297941832724e+14./pow  5.47s user 0.01s system 99% cpu 5.490
>>> total
>>>
>>
>> interesting :)
>>
>> I have:
>>
>> $> gcc --version
>> gcc (GCC) 7.1.1 20170630
>> Copyright (C) 2017 Free Software Foundation, Inc.
>> This is free software; see the source for copying conditions.  There is NO
>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
>> PURPOSE.
>>
>> also interestingly, with clang:
>> $> clang --version
>> clang version 4.0.1 (tags/RELEASE_401/final)
>> Target: x86_64-unknown-linux-gnu
>> Thread model: posix
>> InstalledDir: /usr/bin
>>
>> $> time ./c-code
>>
>> real 0m0.001s
>> user 0m0.001s
>> sys 0m0.000s
>>
>> $> time ./c-code-sum
>> sum=606329794183272.375000
>>
>> real 0m0.228s
>> user 0m0.227s
>> sys 0m0.000s
>>
>> I haven't looked at the assembly to see what's really going on for the
>> GCC version...
>>
>> -s
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to