Thanks. You're right - this is not the way to choose a language. I was just curious. Go has many, many more things going for it - multi core support, networking, standard library, community ...
On Sunday, February 3, 2019 at 8:56:28 PM UTC+2, robert engels wrote: > > It will also depend on which math library and compiler options you use on > the C side. > > I’ll give you a bit of a warning though, if you are making decisions based > solely on tests like this you you might be missing the bigger picture of > the value of systems like Go. > > A simple example, even 1.5 sounds like a lot, as soon as you do any IO > that will fall to about .0000001 percent difference. > > On Feb 3, 2019, at 12:49 PM, Miki Tebeka <miki....@gmail.com <javascript:>> > wrote: > > Yup. Using int32 in Go reduces the difference to 1.5. Thanks > > On Sunday, February 3, 2019 at 8:35:46 PM UTC+2, Robert Engels wrote: >> >> Also the go program is most likely using 64 bit math. Use int32 to >> compare it correctly. >> >> On Feb 3, 2019, at 12:31 PM, Robert Engels <ren...@ix.netcom.com> wrote: >> >> Don’t use rtdsc in the C program use gettimeofday to ensure you are >> comparing the same. >> >> On Feb 3, 2019, at 12:22 PM, Miki Tebeka <miki....@gmail.com> 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...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> >> -- >> 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...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> >> -- > 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...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > -- 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.