Descriptionfmt: Improved printing performance for integers.
Related to issue 3463. The special casing for base10
and base2^n is copied from strconv.Itoa().
Of course this is code duplication which should be avoided
but neither fmt nor strconv expose a usable interface to
use the integer format routine of the other package. Itoa
cannot use fmt.Sprint because there is no format string for
generic bases, fmt cannot use strconv.Itoa because Itoa
does not offer uppercase digits (ABCDEF..).
Performance stats for the following program:
package main
import "fmt"
import "runtime/pprof"
import "os"
import "bufio"
func main() {
f, _ := os.Create("print_buf.prof")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
b := bufio.NewWriter(os.Stdout)
for i := 0; i < 1<<25; i++ {
fmt.Fprintln(b, i)
}
}
=========== Old =============================
User time (seconds): 26.69
System time (seconds): 5.31
Percent of CPU this job got: 138%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:23.04
=========== New =============================
User time (seconds): 14.84
System time (seconds): 2.77
Percent of CPU this job got: 141%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:12.43
Patch Set 1 : diff -r 6b163ec2122a172030284060788f535ab3b9d0e3 https://code.google.com/p/go #Patch Set 2 : diff -r 6b163ec2122a172030284060788f535ab3b9d0e3 https://code.google.com/p/go #Patch Set 3 : diff -r 6b163ec2122a172030284060788f535ab3b9d0e3 https://code.google.com/p/go #MessagesTotal messages: 7
|