Micro optimization is only a small part of the picture. While you can shave off a few ms with micro optimization, you can save much more with macro optimization. Macro optimization deals with algorithm, program design, caching, etc. This is why some people consider language vs language micro-benchmark to be *irrelevant*, because it plays only a very minor part. My colleague is a Haskell guru. Despite Haskell being cast as slow and inefficient in various micro benchmarks, his real-world Haskell programs are very fast that you wouldn't believe they are written in Haskell. He often come up with ingenious solutions to problems. I think Haskell tend to attract bright individuals and programming theoreticians.
I find it funny that people now use C as the golden standard to measure performance. Back then people used to think that C was slow compared to ASM. In fact, C is still slow compared to well-written ASM code. Often, C++ compilers are able to produce much more efficient code compared to C, thanks to some C++ constructs that allow the compilers to make better optimization decision. So C isn't really the *fastest* programming language out there. While micro benchmark may give valuable feedback, do not use it as the sole measure to judge a programming language's merits. At the end of the day, it is the carpenter who makes the furniture and not his fancy hammer. On Monday, February 4, 2019 at 1:22:54 AM UTC+7, Miki Tebeka wrote: > Hi, > > I'm comparing two loops in Go and C. The Go code on my machine is about 3 > times slower than C. I know C can be faster but didn't think it'll be that > faster. Any ideas what's making the Go code slower? > > You can see the code at https://github.com/tebeka/go-c-loop > > Go Code: > package main > > > import ( > "fmt" > "os" > "strconv" > "time" > ) > > > func main() { > n, _ := strconv.Atoi(os.Args[1]) > m, _ := strconv.Atoi(os.Args[2]) > > > sum := int(0) > start := time.Now() > for i := 0; i < 10000000; i++ { > if i%n != m { > sum += n > } > } > > > fmt.Println(time.Now().Sub(start).Seconds(), sum) > } > > > > C Code > #include <stdio.h> > #include <unistd.h> > #include <x86intrin.h> > > > > > int main(int argc,char** argv) { > unsigned long long ull0,ull1; > unsigned int sum=0,n,m; > > > sscanf(argv[1],"%d",&n); > sscanf(argv[2],"%d",&m); > > > ull0 = __rdtsc(); > for(int i=0; i<10000000; i++) { > if(i%n != m) { > sum += n; > } > > > } > > > ull1 = __rdtsc(); > printf("%f %d\n",(ull1-ull0)/2.1e9,sum); > } > > > > -- 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.