[go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread Christian LeMoussel
Thank you Bryan for your advice. In examples, I see how to pass the Go pointers directly. For example : h := C.CString(name) defer C.free(unsafe.Pointer(h)) gerrno, err := C.getaddrinfo(h, nil, &hints, &res) To h := make([]byte, len(name)+1) copy(h, name) gerrno, err := C

[go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-23 Thread Christian LeMoussel
I do this devidx := C.scan_bus((*C.char)(unsafe.Pointer(&sbuf[0])), C.int(cap(sbuf)), C.CString(sn), C.CString(product)) Is it correct /best way ? There is no memory leaks ? . -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsu

[go-nuts] How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-23 Thread Christian LeMoussel
I have a this C function int scan_bus(char *sbuf, int sbuflen, char* sn, char* ps) I'm trying to call this that takes several char * byte buffers as arguments. In Go, I have sbuf in []byte slices. But I can't figure out how to pass these into the C function. I've tried var (

[go-nuts] how to do numpy.fromstring in Go ?

2017-12-06 Thread Christian LeMoussel
I have to write a Python program that uses numpy in GO. I have this Python code : prefix = "de98671db1ce0e5c9ba89ab7ccdca6c427460295b8dd3642e9b2bb961723307c57629b1ad37909a863a56965" prefix_np = np.fromstring(prefix[0:64], dtype=np.uint32, count=16) print("prefix_np: {}".format(prefix_np))

[go-nuts] Re: How to find optimal value for GOGC?

2017-11-17 Thread Christian LeMoussel
Interesting article. However, it does not describe the script/bench to find the best value, from 100 to 20,000, in increments of 100. -- 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

[go-nuts] How to find optimal value for GOGC?

2017-11-16 Thread Christian LeMoussel
Go has the GOGC variable, that can also be controlled with the SetGCPercent function in the runtime/debug package. Is it possible to find the optimal value of GOGC to get the most op / s per report to the number of cores? -- You received this message because you are subscribed to the Google

[go-nuts] Re: How to optimize?

2017-11-15 Thread Christian LeMoussel
. . 83:LoopSearch: 20ms 20ms 84: for i = 0; i < lenBufferHexHash; i++ { 90ms 90ms 85: hhi0, hhi1 := bufferHexHash[i], bufferHexHash[i+1] 390ms 390ms 86: for j = 0; j < lenBufferHexSearch; j++ { 710ms

[go-nuts] Re: How to optimize?

2017-11-15 Thread Christian LeMoussel
bFind = true >break LoopSearch >} >} >} > > 2017. november 15., szerda 18:15:32 UTC+1 időpontban Christian LeMoussel a > következőt írta: >> >> Hi, >> >> I have this program (https://play.golang.org/p/qHPzjj2uj3) that take a >>

Re: [go-nuts] How to optimize?

2017-11-15 Thread Christian LeMoussel
@Jan, Why not but I don't understand. Because if I do startTime = time.Now() for i := 0; i < 1000; i++ { result = bytes.Index([]byte(hash), []byte(toSearch)) != -1 } fmt.Printf("bytes.Contains Find: %t Time : %.2f sec.\n", result, time.Now().Sub(st

[go-nuts] Re: How to optimize?

2017-11-15 Thread Christian LeMoussel
I created benchmarks : https://play.golang.org/p/kgBsciRbpe BenchmarkByteIndex-2 500 210 ns/op 64 B/op 1 allocs/op BenchmarkByteIndexPointeur-2200090.1 ns/op 0 B/op 0 allocs/op BenchmarkFindByte-2

[go-nuts] How to optimize?

2017-11-15 Thread Christian LeMoussel
Hi, I have this program (https://play.golang.org/p/qHPzjj2uj3) that take a decent amount of time for computing. Let’s open pprof and see what it spent its time on. Type: cpu Time: Nov 15, 2017 at 5:48pm (CET) Duration: 9.92s, Total samples = 9.78s (98.54%) Entering interactive mode (type "help"

[go-nuts] How to returns the index of the first instance in uint32 slice?

2017-11-14 Thread Christian LeMoussel
bytes package implements Index function (func Index(s, sep []byte) int) that returns the index of the first instance of sep in s, or -1 if sep is not present in s. Do you think it's possible to do the same thing with uint32 slice (func Index(s, sep []uint32

[go-nuts] Re: How to convert from []byte to []uint32?

2017-11-14 Thread Christian LeMoussel
.Thank you Peter & Bryan for your help, it's very instructive. I realized a Bench with all your solutions: https://play.golang.org/p/ePKkHNqTot BenchmarkCharToInt32_0 : my original solution BenchmarkCharToInt32_1 : Bryan "code golf" solution. https://play.golang.org/p/Jxkf2Vheml BenchmarkHexToU

Re: [go-nuts] Re: OpenCL or CUDA bindings

2017-11-13 Thread Christian LeMoussel
For CUDA you have, cu package that provides an idiomatic interface to the CUDA Driver API. https://github.com/chewxy/cu -- 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 ema

[go-nuts] How to convert from []byte to []uint32?

2017-11-12 Thread Christian LeMoussel
I have a data stream of bytes and I'd like to get array of int32 (from four bytes). func convertCharToInt32(buffer string) []uint32 { const SIZEOF_INT32 = 4 var hh = make([]byte, 2) var cbuffer = make([]byte, len(buffer)/2) var hbuffer = make([]uint32, len(cbuffer)/SIZEOF_INT32)

Re: [go-nuts] Re: How can I convert an byte array into int array?

2017-11-12 Thread Christian LeMoussel
ampaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> 2017-11-12 12:36 GMT+01:00 Jan Mercl <0xj...@gmail.com>: > On Sun, Nov 12, 2017 at 11:48 AM Christian LeMoussel > wrote: > > > To detect byte order for golang, I find this package GoE

[go-nuts] Re: How can I convert an byte array into int array?

2017-11-12 Thread Christian LeMoussel
To detect byte order for golang, I find this package* GoEndian * -- 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

[go-nuts] Re: How can I convert an byte array into int array?

2017-11-12 Thread Christian LeMoussel
I find this solution : const SIZEOF_INT32 = 4 var cbuffer = make([]byte, 28) var hbuffer = make([]uint32, len(cbuffer)/SIZEOF_INT32) for i := range hbuffer { hbuffer[i] = uint32(binary.LittleEndian.Uint32(cbuffer[i*SIZEOF_INT32 : (i+1)*SIZEOF_INT32])) } By default,

[go-nuts] How can I convert an byte array into int array?

2017-11-12 Thread Christian LeMoussel
I have []byte, How can I convert this to []int? var cbuffer = make([]byte, 28) var hbuffer = [8]int{0, 0, 0, 0, 0, 0, 0} -- 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 e

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
I found why.. hash.Hash interface does not have a .Copy, -- 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+unsubs

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
I optimize like this // Copy returns a copy of hash.Hash func (d *digest) Copy() hash.Hash { dCopy := *d return &dCopy } But I got error d1.Copy undefined (type hash.Hash has no field or method Copy) with this code d1 := sha256.New() d2 := sha256.New() d1.Write([]byte("a")

Re: [go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
JB, Thank you very much for your help. For adding a copy method direcly on sha256.digest, I propose this // Copy returns a copy of hash.Hash func (d *digest) Copy() hash.Hash { dh := new(digest) dh.h = d.h dh.x = d.x dh.nx = d.nx dh.len = d.len dh.is224 = d.is224 retu

[go-nuts] Efficient to copy Hash?

2017-11-08 Thread Christian LeMoussel
Hi, I want to calculate hash on 3 strings. First string is always the same, the other may vary. The first approach is to calculate the hash each time for the 3 strings ( BenchmarkHash) Another approach would be to calculate once for the first string, and then reuse this hash to calculate the ha

[go-nuts] How to use HTTP proxy with net.Dial on TCP network?

2017-10-31 Thread Christian LeMoussel
I use net.DialTimeou to connects to endpoint address on "tcp" network conn, err := net.DialTimeout("tcp", endpoint, connectionTimeout) if err != nil { return nil, err } Is it possible to use HTTP proxy (http://111.222.333.444:3128) with net.Dial on TCP network? How can I d

[go-nuts] Re: Golang goroutine slow down when adding concurrency

2017-10-27 Thread Christian LeMoussel
@Jake, I start in Go. I'm not familiar with the use of pprof. I do this go tool pprof -list=calculate goRoutineBench /tmp/profile152563623/cpu.pprof I get this Total: 1.84mins ROUTINE main.calculate in goRoutineBench.go 1.84mins 1.84mins (flat, cum) 99.86% of Total

[go-nuts] Golang goroutine slow down when adding concurrency

2017-10-27 Thread Christian LeMoussel
Hi, I am studying about golang and use of goroutine. With this sample code, on my PC with 4 logical CPUs, I can't understand why I don't have any performance improvement. If I add in concurrency, the time it takes to do tends to slow down by the original without concurrency. 2017/10/27

[go-nuts] Re: Perfomance - sha256 Encoding to Hex

2017-10-17 Thread Christian LeMoussel
OK, I'm new in GO. As you indicate I will profiling by writing a standard testing.B benchmark. Thanks -- 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

[go-nuts] Perfomance - sha256 Encoding to Hex

2017-10-17 Thread Christian LeMoussel
I need to calculate 10 millions of sha256 checksums, Actually I do this : var bl int var pnb = make([]byte, 10) var hash = [32]byte var sha256Hash string var steps = 1000 startBench := time.Now() for i := 0; i < steps; i++ { bl = 0 bl += copy(pnb[bl:], "TEST") bl += copy(nonce

[go-nuts] How to generate long int with k random bits.

2017-10-13 Thread Christian LeMoussel
Hi, In python there is random. getrandbits(*k* ) that returns a python long int with *k* rando

[go-nuts] Re: How to convert JSON message to Go struct

2017-10-11 Thread Christian LeMoussel
It's OK.Thank you very much. -- 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.goog

[go-nuts] Re: How to convert JSON message to Go struct

2017-10-11 Thread Christian LeMoussel
Ok but how can I acces four values? I do this segments = []byte("[[\"19c87d4ddf59160406821ca102aa4f49846ecf5ac3d41d2007883834\", 75, \"b54317cb538c6b3a5ae8b84f8b53c83652037038ad8ad6bef4c8b43a\", 101]]") var workPack [][]interface{} err = json.Unmarshal(segments, &workPack) chec

[go-nuts] How to convert JSON message to Go struct

2017-10-10 Thread Christian LeMoussel
Hi, I'm new to Go, I have difficulty to converts JSON into a Go type definition. *JSON* [["19c87d4ddf59160406821ca102aa4f49846ecf5ac3d41d2007883834", 75, "b54317cb538c6b3a5ae8b84f8b53c83652037038ad8ad6bef4c8b43a", 101]] *Go type definition with JSON-to-Go Convert

Re: [go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Christian LeMoussel
connections.send(s, "getwork", 10) I searched a little bit more and here is in Python send() function def send(sdef, data, slen): sdef.setblocking(0) sdef.sendall(str(len(str(json.dumps(data.encode("utf-8" ).zfill(slen)) sdef.sendall(str(json.dumps(data)).encode("utf-8"))

[go-nuts] How to covert simple RPC Call in Python to Go?

2017-10-10 Thread Christian LeMoussel
I'm having trouble translating Python code into GO. s = socks.socksocket() s.connect((mining_ip_conf, int(port))) # connect to pool connections.send(s, "getwork", 10) work_pack = connections.receive(s, 10) db_block_hash = (work_pack[-1][0]) diff = int((work_pack[-1][1])) paddress = (work_pac