[go-nuts] Re: why do we need generic thread.

2017-08-04 Thread Lucio
We know how to deal with that without generics. But how would you define generics to address that more elegantly than you would with already available Go constructs (type assertions)? Lucio. On Saturday, 5 August 2017 01:48:28 UTC+2, T L wrote: > > A case: > > func iterateAndCopy(slice []T, p *

[go-nuts] Re: Generics are overrated.

2017-08-04 Thread Lucio
(Some unjustifiable opinionated ramblings from a faraway place, read at your peril.) It took Dijkstra quite some effort to accept the concept of "interrupts" (quotation anyone?), but eventually he went with it. Resistance to operator overloading is as admirable as it is futile. Ultimately, the

[go-nuts] Re: [Ann] Generating go struct from json/yaml

2017-08-04 Thread Aditya Mukerjee
> Is it still being maintained Absolutely; in fact, it's a critical part of the build process for our metrics pipeline , which is the core of my work. Thank you for your submissions. I'm the primary maintainer and have been traveling for the last couple of w

Re: [go-nuts] liteide x32.2 released

2017-08-04 Thread djadala
apt-get install apt-file apt-file update apt-file search libpng12.so libpng12-0: /lib/x86_64-linux-gnu/libpng12.so.0 libpng12-0: /lib/x86_64-linux-gnu/libpng12.so.0.50.0 libpng12-0: /usr/lib/x86_64-linux-gnu/libpng12.so.0 libpng12-dev: /usr/lib/x86_64-linux-gnu/libpng12.so On Friday, August 4,

[go-nuts] Re: Generics are overrated.

2017-08-04 Thread as . utf8
I'm hesitant to accept generics due to the fear of *overloaded operators *being the next big deal*. *C# even has *properties (user-defined methods dispatched upon an assignment operation)*. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To un

[go-nuts] Re: Error when using go tool trace

2017-08-04 Thread evan . explodes
Ah, excellent. Good catch. I learned something about defer. The ordering of the close was my problem, however. The way I *actually* handle closing the trace is: func (t *FileTracer) Stop() error { if t == nil { return nil } trace.Stop() return t.f.Close() } On Friday, August 4, 2017 at 12:42:31

[go-nuts] why do we need generic thread.

2017-08-04 Thread T L
A case: func iterateAndCopy(slice []T, p *T) { for _, v := range slice { *p = v } } func Benchmark_CopyCosts(b *testing.B) { b.Run("bool-4", func(b *testing.B){ iterateAndCopy(make([]bool, 4), new(bool)) }) b.Run("int32-4", func(b *testing.B){ iterateAn

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
Thanks, Peter. I actually don't mind a larger code if the performance can be improved. Also, we probably do computations more often with smaller integers (at least in my applications); that's why I overlooked the case greater than 10... But now I'm using your (+Michael Jones and others) sugges

Re: [go-nuts] "fallthrough statement out of place" in `if` block inside `swicth` block

2017-08-04 Thread T L
On Friday, August 4, 2017 at 6:59:41 PM UTC-4, Doğan Kurt wrote: > > Fallthrough must be a design choice but goto's restriction is a necessity. > > What happens if you jump into the middle of an if block? You skipped the > condition check, you run the code after the goto label, what about the c

Re: [go-nuts] "fallthrough statement out of place" in `if` block inside `swicth` block

2017-08-04 Thread Doğan Kurt
Fallthrough must be a design choice but goto's restriction is a necessity. What happens if you jump into the middle of an if block? You skipped the condition check, you run the code after the goto label, what about the code before the label, there might be some variables initialized, and how wi

Re: [go-nuts] "fallthrough statement out of place" in `if` block inside `swicth` block

2017-08-04 Thread T L
On Tuesday, August 1, 2017 at 8:41:21 AM UTC-4, Jan Mercl wrote: > > On Tue, Aug 1, 2017 at 2:34 PM Fumi Takeuchi > wrote: > > > Example code: https://play.golang.org/p/dVtPVt3oKt > > > > Maybe `fallthrough` statement cannot be used in `if` block even if it's > put inside `swicth` block) > > Tr

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Michael Jones
Dorival, There is a great deal to learn from this issue. Some interesting issues: Exponentiation by arbitrary real or complex powers is a little complicated to evaluate quickly with accuracy. Other than special cases, you're forced toward x**y ==> Exp(y*Log(x)), where each of Exp() and Log() are

[go-nuts] Re: When to use custom string type and custom int type

2017-08-04 Thread T L
On Thursday, August 3, 2017 at 12:55:44 PM UTC-4, Kaviraj Kanagaraj wrote: > > Can someone help me understand whats the main difference two different > UserType in below snippet.? > > More importantly when to use which. > > ``` > type UserType string > > const ( > Undefined UserType = "undefined

[go-nuts] Re: gitcreepy – get GitHub users' previous email addresses from all their historical commits!

2017-08-04 Thread as . utf8
This information is actually stored in the git commits themselves. There is a zlib'd field that contains the author's name and email address for each commit in the repo. A complete transcript for every commit can be reconstructed from a git repo in this manner. On Saturday, July 15, 2017 at 5:5

Re: [go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread zack . scholl
Thanks, this looks great On Friday, August 4, 2017 at 10:34:41 AM UTC-6, rog wrote: > > Ah, and I just found another version, somewhat simpler, > that just reads bytes in reverse: > > https://play.golang.org/p/mYsP7iHmiW > > > On 4 August 2017 at 16:43, roger peppe > > wrote: > > I wrote this

[go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread Tamás Gulácsi
I meant mmap, sorry. -- 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

Re: [go-nuts] Swig, Shared C++ library and Go not working

2017-08-04 Thread il
Tried it. I need help with Swig and Shared lib пятница, 4 августа 2017 г., 21:37:32 UTC+3 пользователь Ian Lance Taylor написал: > > On Fri, Aug 4, 2017 at 8:08 AM, il > > wrote: > > Your method is good for static linking. > > Not for Shared C++ library > > Add a .go file with > > /* > #cgo

[go-nuts] Re: Is x/exp/shiny dead?

2017-08-04 Thread as . utf8
It's not ready for general use, but it certainly isn't dead. I think a lack of examples for some of the more-complex widgets is probably where it needs the most help, but considering that only one person is working on it the result is a very impressive addition to the Go ecosystem. I've not used

Re: [go-nuts] Swig, Shared C++ library and Go not working

2017-08-04 Thread Ian Lance Taylor
On Fri, Aug 4, 2017 at 8:08 AM, il wrote: > Your method is good for static linking. > Not for Shared C++ library Add a .go file with /* #cgo LDFLAGS: -lmylib */ import "C" to get system linker flags. Ian > пятница, 4 августа 2017 г., 18:07:15 UTC+3 пользователь Ian Lance Taylor > написал: >>

[go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread Tamás Gulácsi
Mmqp the file and push the hard work to the kernel? -- 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, vi

Re: [go-nuts] all goroutines are asleep - deadlock!

2017-08-04 Thread Shawn Milochik
On Fri, Aug 4, 2017 at 11:45 AM, Jannick Fahlbusch wrote: > Hi, > > you need to spin up another goroutine which ranges over the channel: > https://play.golang.org/p/OhLd6vOBYE > > > This has a race condition. There's no guarantee that all the lines will be printed before main() exits. A better so

Re: [go-nuts] all goroutines are asleep - deadlock!

2017-08-04 Thread Jannick Fahlbusch
Hi, you need to spin up another goroutine which ranges over the channel: https://play.golang.org/p/OhLd6vOBYE The reason for the deadlock is: You spin up N workers which are sending the results over the "fact_chan"-Channel. After you did this, you are listening on the main-routine for messages on

Re: [go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread roger peppe
Ah, and I just found another version, somewhat simpler, that just reads bytes in reverse: https://play.golang.org/p/mYsP7iHmiW On 4 August 2017 at 16:43, roger peppe wrote: > I wrote this code a while ago to accomplish a similar task > (actually I wanted to scan lines in reverse, but it works >

Re: [go-nuts] liteide x32.2 released

2017-08-04 Thread Oleg Puchinin
liteidex32.2.linux64-qt4.tar.bz2 $ bin/liteide say ./liteide: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory Debian 9.1 Oleg. 2017-07-1

[go-nuts] Re: "fallthrough statement out of place" in `if` block inside `swicth` block

2017-08-04 Thread Fumi Takeuchi
Thanks a lot for your polite and convenient replies. This time, I decided to use nested if-else instead of switch-fallthrough. As all of you mentioned, I have to avoid this. Maybe it's not Go style. What I actually want to write is very little router that determines which to provide converted fi

Re: [go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread roger peppe
I wrote this code a while ago to accomplish a similar task (actually I wanted to scan lines in reverse, but it works for bytes too, because it works with bufio.ScanBytes): https://play.golang.org/p/dqmlmdqk9k If you were going to use it in production, it would need lots of tests - it may well be

Re: [go-nuts] all goroutines are asleep - deadlock!

2017-08-04 Thread Shawn Milochik
Nothing ever closes the channel, so your last "for" loop blocks reading from it. A possible solution: https://play.golang.org/p/mKdzU1z6Tx -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails f

[go-nuts] all goroutines are asleep - deadlock!

2017-08-04 Thread prankplayer
*Factorial Program in GoLang. Encountering deadlock.* *Hello All,* I am pretty new to GoLang , so please excuse me if question/doubt is silly. I am trying to write a Factorial program of numbers ranging from 0 to 5. My goal is to launch separate GO routines for each number and then collect o/p

Re: [go-nuts] Swig, Shared C++ library and Go not working

2017-08-04 Thread il
Your method is good for static linking. Not for Shared C++ library пятница, 4 августа 2017 г., 18:07:15 UTC+3 пользователь Ian Lance Taylor написал: > > On Fri, Aug 4, 2017 at 7:20 AM, il > > wrote: > > I wanna use precomplied c++ library. I make test project for it. > > > > > > Mac OS Sierr

[go-nuts] Is there a way to do bufio.ReadByte() starting at the end of a Reader?

2017-08-04 Thread zack . scholl
I'm working on a finite state machine that processes a file byte by byte, without loading the entire file into memory. Currently it works in the forward direction, but I'd like to get it working in the reverse direction as well. Currently I make a *bufio.Readerfrom a open file / response body

Re: [go-nuts] Swig, Shared C++ library and Go not working

2017-08-04 Thread Ian Lance Taylor
On Fri, Aug 4, 2017 at 7:20 AM, il wrote: > I wanna use precomplied c++ library. I make test project for it. > > > Mac OS Sierra Apple LLVM version 8.0.0 (clang-800.0.42.1) > > GO: go1.8.3 darwin/amd64 > SWIG Version 3.0.12 > > > swig -c++ -go -soname libapple.dylib -use-shlib -intgosize 64 core/A

[go-nuts] gopherjs files, writing, loading

2017-08-04 Thread snmed
Hi "me" I don't know gopherjs well, but as far as I know, they only provide an api to the html 5 feature localStorage and sessionStorage, see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage so you can't write directly to the filesystem with js via a browser. Cheers snmed

Re: [go-nuts] accept(2), runtime.LockOSThread and goroutine scheduling

2017-08-04 Thread Ian Lance Taylor
On Fri, Aug 4, 2017 at 1:27 AM, Konstantin Khomoutov wrote: > > We're experiencing a problem with our program which serves HTTP requests. > > Its clients have TCP connection timeouts set to 1 second, and under > certain pattern of heavy load the server fails to perform some > net.netFD.Accept() ca

[go-nuts] Re: gopherjs files, writing, loading

2017-08-04 Thread Tong Sun
Not to answer your question, but a request rather, Would you change your name to something else, other than "me" please? The way google group works is that all our own posts are classified as "By me" by google group, and your post is cluttering everyone's view, if they are trying to find post

[go-nuts] Re: [Ann] Generating go struct from json/yaml

2017-08-04 Thread Tong Sun
On Sunday, July 16, 2017 at 11:42:34 PM UTC-4, Aditya Mukerjee wrote: > > Glad to see you're finding gojson useful. Let us know if you have > suggestions; if there are improvements which would be helpful for people in > general, we'd be happy to merge them upstream. > Is it still being maintai

[go-nuts] Swig, Shared C++ library and Go not working

2017-08-04 Thread il
I wanna use precomplied c++ library. I make test project for it. Mac OS Sierra Apple LLVM version 8.0.0 (clang-800.0.42.1) GO: go1.8.3 darwin/amd64 SWIG Version 3.0.12 swig -c++ -go -soname libapple.dylib -use-shlib -intgosize 64 core/Apple.i And I see Apple_gc.c and wanna compile with 6c(

Re: [go-nuts] Calling a C function from Go code in cgo must new a thread

2017-08-04 Thread bysui hou
I get it. Thanks a lot 在 2017年8月4日星期五 UTC+8下午8:52:36,Konstantin Khomoutov写道: > > On Fri, Aug 04, 2017 at 03:45:49AM -0700, bysui hou wrote: > > > I'm going to use CGO to call c++ in my project and do some > performance > > tests. So I do research on cgo, and find that calling a C function f

Re: [go-nuts] Size of struct{}?

2017-08-04 Thread Konstantin Khomoutov
On Fri, Aug 04, 2017 at 02:25:01AM -0700, 樊冰心 wrote: [...] > type T struct { > i int > x struct{} > } > > func main() { > var t T > fmt.Println(unsafe.Sizeof(t)) > } > > Since size of struct{} is 0, why the result is 16? Consider also reading https://dave.cheney.net/2014/03/25/the-empty-struct

Re: [go-nuts] Calling a C function from Go code in cgo must new a thread

2017-08-04 Thread Konstantin Khomoutov
On Fri, Aug 04, 2017 at 03:45:49AM -0700, bysui hou wrote: > I'm going to use CGO to call c++ in my project and do some performance > tests. So I do research on cgo, and find that calling a C function from Go > code won't block other goroutines from running. I view the cgocall code > (runti

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread peterGo
Dorival Pedroso, PowP has a lot of code. PowG is simpler and it is modestly slower for small values of n and much faster for larger values of n. func PowG(x float64, n uint32) float64 { y := 1.0 for i := n; i > 0; i >>= 1 { if i&1 == 1 { y *= x } x *=

[go-nuts] Re: Size of struct{}?

2017-08-04 Thread Dave Cheney
This was issue https://github.com/golang/go/issues/9401 The short version of it is even though the size of x is zero, x and i are not permitted to occupy the same address in memory. This means the address of T.x could be beyond the bounds of t, so if x is the final field in the struct, it is as

[go-nuts] Calling a C function from Go code in cgo must new a thread

2017-08-04 Thread bysui hou
I'm going to use CGO to call c++ in my project and do some performance tests. So I do research on cgo, and find that calling a C function from Go code won't block other goroutines from running. I view the cgocall code (runtime/cgocall.go, is there any official doc?), it seems that calling a

[go-nuts] Size of struct{}?

2017-08-04 Thread 樊冰心
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" package main import ( "fmt" "unsafe" ) type T struct { i int x struct{} } func main() { var t T fmt.Println(unsafe.Sizeof(t)) } Since size of struct{} is 0, why the result is 16? -- You received this message

Re: [go-nuts] [CGO] how to pass a 2d slice to C?

2017-08-04 Thread Konstantin Khomoutov
On Fri, Aug 04, 2017 at 02:09:14AM -0700, jianzhang...@gmail.com wrote: > Hey Guys, > > I'm in trouble in the same issue. My code as the following: > > test.go > ```go > name := []string{"gpu0", "gpu1", "gpu2", "gpu3"} > matrix := [3][3]int{{1, 0, 0}, {3, 3, 0}, {3, 3, 2}} > > C.tes

[go-nuts] Re: Go Styleguide

2017-08-04 Thread Henry
I disagree with some of the points: *Structured logging* - It depends on the context. Unnecessary information may obscure the clarity of the log message. *Use assert-libraries* - Okay, but not necessary. I would avoid depending on too many third party libraries for better stability (your code d

Re: [go-nuts] [CGO] how to pass a 2d slice to C?

2017-08-04 Thread jianzhangbjz
I have changed the go code into the below, but still got error. Something else I missed? gonameunits := []string{"gpu0", "gpu1", "gpu2", "gpu3"} nameunits := make([]*C.char, len(gonameunits)) for i, _ := range gonameunits { nameunits[i] = C.CString(gonameunits[i]) defe

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
Since my ASM skills are limited, for positive integers, I'm planning on using: // PowP computes real raised to positive integer xⁿ func PowP(x float64, n uint32) (r float64) { if n == 0 { return 1.0 } if n == 1 { return x } if n == 2 { return x * x } if n == 3 { return x * x * x } if n == 4 { r =

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Henrik Johansson
Ah of course that explains it. On Fri, 4 Aug 2017, 11:22 Dave Cheney, wrote: > Gcc on OS X is an alias for clang as Apple does not ship any GPLv3 > software with their os. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe f

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Dave Cheney
Gcc on OS X is an alias for clang as Apple does not ship any GPLv3 software with their os. -- 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..

Re: [go-nuts] [CGO] how to pass a 2d slice to C?

2017-08-04 Thread jianzhangbjz
Hey Guys, I'm in trouble in the same issue. My code as the following: test.go ```go name := []string{"gpu0", "gpu1", "gpu2", "gpu3"} matrix := [3][3]int{{1, 0, 0}, {3, 3, 0}, {3, 3, 2}} C.test_settopologyresource(mod, C.CString("node1"), C.int(2), (**C.char)(unsafe.Pointer(&name[0])

Re: [go-nuts] Re: gobind generated constructor for struct containing []byte sometimes corrupts data

2017-08-04 Thread Elias Naur
Den fre. 4. aug. 2017 01.26 skrev Antonio Marcedone : > Thanks! The only information I could find about this on the gobind > documentation is (https://godoc.org/golang.org/x/mobile/cmd/gobind) > > - Byte slice types. Note that byte slices are passed by reference, > and support mutation. > > Howe

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Henrik Johansson
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

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Dave Cheney
even at -O3 gcc wouldn't do it, probably because pow is implemented in another compilation unit. On Fri, Aug 4, 2017 at 6:49 PM, Sebastien Binet wrote: > > > On Fri, Aug 4, 2017 at 10:47 AM, Dave Cheney wrote: >> >> I'm disappointed that both compilers didn't compile both original samples >> to

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Sebastien Binet
On Fri, Aug 4, 2017 at 10:47 AM, Dave Cheney wrote: > I'm disappointed that both compilers didn't compile both original samples > to a noop. > clang did it, though. -s -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this g

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Dave Cheney
I'm disappointed that both compilers didn't compile both original samples to a noop. -- 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...@goo

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Egon
And the guess how it's arriving at that optimization: Step 0: base code x := 2.5 res := 0.0 for n := 0; n < NMAX; n++ { for i := 0; i < 4; i++ { res += math.Pow(x, float(i)) } } Step 1: unroll inner-loop x := 2.5 res := 0.0 for n := 0; n < NMAX; n++ { res += math.Pow(x, float(0)) res += math.Po

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Egon
Use the Assembly Luke. https://godbolt.org/g/nGFMbf It looks like clang manages to compute a table of powers of x. Which, is very very impressive. Which is roughly https://play.golang.org/p/CZkiJKfe7s -- except clang, also does inner loop unrolling. + Egon On Friday, 4 August 2017 11:16:10 U

[go-nuts] accept(2), runtime.LockOSThread and goroutine scheduling

2017-08-04 Thread Konstantin Khomoutov
We're experiencing a problem with our program which serves HTTP requests. Its clients have TCP connection timeouts set to 1 second, and under certain pattern of heavy load the server fails to perform some net.netFD.Accept() calls in time so a fraction of clients gets I/O timeouts when attempting t

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
I've put these files and a bash script for convenience here: https://gist.github.com/cpmech/b13b6e17789c0bdfa469b2f1b6b71587 Thanks again. On Friday, August 4, 2017 at 6:16:10 PM UTC+10, Dorival Pedroso wrote: > > wait, what?! > > the same code: > > #include "stdio.h" > #include "math.h" > int m

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
wait, what?! the same code: #include "stdio.h" #include "math.h" int main() { double res = 0.0; double x = 2.5; int Nmax = 1000; for (int N=0; N > > > On Fri, Aug 4, 2017 at 9:51 AM, Henrik Johansson > wrote: > >> Actually I get the same as the original program on my mac. >>

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Sebastien Binet
On Fri, Aug 4, 2017 at 9:51 AM, Henrik Johansson 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.4

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
Sebastien is right! Thanks a lot! I forgot that the optimizer does eliminate some code at times. (and forgot this https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go) This is the C code now (compiled with gcc -O2 run_std_pow.c -o run_std_pow -lm): #include "stdio.h" #include "math

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Henrik Johansson
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 fre 4 aug. 2017 kl 09:38 skrev

Re: [go-nuts] How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Sebastien Binet
Dorival, On Fri, Aug 4, 2017 at 8:20 AM, Dorival Pedroso wrote: > I've noticed that this C code: > > #include "math.h" > int main() { > double x = 2.5; > int Nmax = 1000; > for (int N=0; N for (int i=0; i<20; i++) { > pow(x, i);

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
again i'm wrong :( On Friday, August 4, 2017 at 10:30:14 AM UTC+3, Sebastien Binet wrote: > > > > On Fri, Aug 4, 2017 at 9:24 AM, > wrote: > >> Ok, >> i'm not right,pow in C is : >> float powf(float x, float y); >>long double powl(long double >> >> use float32 pow for proper comparison o

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Sebastien Binet
On Fri, Aug 4, 2017 at 9:24 AM, wrote: > Ok, > i'm not right,pow in C is : > float powf(float x, float y); >long double powl(long double > > use float32 pow for proper comparison or use powl for C double wersion. > C'pow is with doubles (like Go's math.Pow): https://linux.die.net/man/3/

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
Ok, i'm not right,pow in C is : float powf(float x, float y); long double powl(long double use float32 pow for proper comparison or use powl for C double wersion. This is demonstartion how when you use go long time, you lose ability to read other languages :) On Friday, August 4, 2017

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
You are comparing apples to oranges( integer vs float64 pow), use integer pow and compare again: func Pow(a, b int) int { p := 1 for b > 0 { if b&1 != 0 { p *= a } b >>= 1 a *= a