go 用 strings.Builder
代替普通的 +
号拼接, 在本人的项目中性能有 8 ~15倍的提升,之前写的太差了。
golang code
代码是很简单的
package main
func main(){
var puts fmt.Sprintf
var builder strings.Builder
builder.WriteString(puts("0x%x,", blkHash))
builder.WriteString(puts("%d,", blkHeader.Number))
builder.WriteString(puts("0x%x,", getFromAddr(tx, big.NewInt(int64(i)))))
builder.WriteString(puts("0x%x,", txGas))
builder.WriteString(puts("0x%x,", txGasPrice))
builder.WriteString(puts("0x%x,", tx.Hash()))
builder.WriteString(puts("0x%x,", txInput))
builder.WriteString(puts("%v,", txNonce))
builder.WriteString(puts("%v,", txTo))
builder.WriteString(puts("%v,", txValue))
builder.String()
}
参考:
网友评论