Skip to content

strconv: not as fast as C #3725

@gopherbot

Description

@gopherbot

by qinhui99:

I found a very bad performance for strconv of Go.  I did some tests between Go and JAVA
for string function. You can see the test results, Go has a very bad performance
comparing  JAVA.  The strconv function is very bad performance and needed to do some
refactoring. Since the   strconv function is very important basic stone of Go , so I
need your help. Thanks

1. float32 to string
Go version: (GO 1.0.1, winxp)
go test ftoa_test.go -bench="."
BenchmarkFloat32ToStr     100000             12812 ns/op
ok      command-line-arguments  1.938s 
 
Java version: (JDK1.7 ,winxp , use the "-server" jvm parameter) 
Loop 10000000 times
Time costs 2.45952435 (s).
performance:2459 ns/op

2.  int32 to string
Go version: (GO 1.0.1, winxp)
go test  itoa_test.go -bench="."
BenchmarkFormatIntByQH    500000              2843 ns/op
ok      command-line-arguments  1.797s

Java version: (JDK1.7 ,winxp , use the "-server" jvm parameter) 
Loop 10000000 times
Time costs 0.695598031 (s).
performance:695 ns/op

3. float64 to string
Go version:
go test ftoa_test.go -bench="."
BenchmarkFloat32ToStr     200000             13046 ns/op
BenchmarkFloat64ToStr     100000             22656 ns/op
ok      command-line-arguments  5.594s

JAVA version:(JDK1.7 ,winxp , use the "-server" jvm parameter)
Loop 10000000 times
Time costs 5.079030794 (s).
performance:5079 ns/op

Attachments:

  1. itoa_test.go (1375 bytes)
  2. ftoa_test.go (1882 bytes)
  3. AtoStringBenchmarkTest.java (613 bytes)
  4. DoubleToStringBenchmarkTest.java (664 bytes)
  5. FloatToStringBenchmarkTest.java (666 bytes)
  6. BenchmarkTest.java (523 bytes)
  7. B.java (74 bytes)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions