Nice! Is "bytconv" shared somewhere?--On Thu, Aug 31, 2017 at 10:53 AM, peterGo <go.pe...@gmail.com> wrote:Michael,
n your code, you have :
const n = 1000 * 1000
for i := 0; i < n && scan.Scan(); i++ {
d, _ := strconv.Atoi(scan.Text())
array[i] = int64(d)
}
https://play.golang.org/p/SgpAXyvsGs
Here's a benchmark that demonstrates the fundamental issue, unnecessary string conversions.
,
BenchmarkAtoiBytconv-4 50000000 30.4 ns/op 0 B/op 0 allocs/op
BenchmarkAtoiStrconv-4 20000000 102 ns/op 8 B/op 1 allocs/op
https://play.golang.org/p/oSQ8RZeGL7
Peter
On Thursday, August 31, 2017 at 12:24:20 PM UTC-4, peterGo wrote:Michael,
Your read times look slow to me. I used bytconv instead of strconv.
bytconv:
read 1000000 98.517584ms
sort 1000000 481.994354ms
strconv:
read 1000000 174.720883ms
sort 1000000 479.437831ms
bytconv is the missing Go standard library package. bytconv is the byte input analog of string input strconv.
Peter
On Wednesday, August 30, 2017 at 7:43:49 PM UTC-4, Michael Jones wrote:good point. I was trying to show that the buffered stdin was "just like" normal scanning but the performance was less compared to the updated scanning code.here is another version, this time with a data generator and since the input is line oriented, the default split function is fine.read 1000000 65.362993mssort 1000000 187.092493msOn Wed, Aug 30, 2017 at 2:56 PM, Patrick Smith <pat42...@gmail.com> wrote:That is simpler, but slower. Not nearly as slow as using unbuffered io though. Timings on my machine, reading 1e6 integers chosen randomly from the range [0,1e18):Original code https://play.golang.org/p/grB-muK7hw5.626974435s155.367779msOriginal poster's optimized code https://play.golang.org/p/1Aoxwwv-zo168.638597ms150.923225msMichael's simpler code https://play.golang.org/p/tMyipz6sYU954.543351ms166.710399msSo this is about 6 times slower. My guess is this is due to the use of reflection in fmt.Fscanf. But that is just a guess; I don't really have any evidence to back it up.On Wed, Aug 30, 2017 at 1:33 PM, Michael Jones <michae...@gmail.com> wrote:This can be much simpler...--On Wed, Aug 30, 2017 at 7:55 AM, Nilsocket <nils...@gmail.com> wrote:Can you provide example code for how you read the input?Both of them were given same input size is:1000000, (i.e., 1 million)// Time taken to read input : 9.840256889s// Time taken to sort: 731.469604msI have implemented the same using bufio:// Time taken to read input : 377.038152ms// Time taken to sort: 688.20638ms--
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.
--Michael T. Jones
michae...@gmail.com
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.
--Michael T. Jones
michae...@gmail.com--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--Michael T. Jones
michae...@gmail.com
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'd also be very interested in looking at 'bytconv'. And most probably should use it in anger :)
If there is performance data, please share.
Strings are immutable, slices arent. Doesnt this make a string the optimal read only data structure for storing and passing around a run of bytes?
If there is performance data, please share.
I suspect that this kind of performance issue may be fixed by better
compiler optimisation in the future (I think should be possible for
the compiler to notice that the string doesn't escape and pass a
pointer to the byte slice as the string argument).
func foo(s string)...bs := []byte{0, 1, 2}s := string(bs)bs[0] = 42foo(s)