golang
文章平均质量分 50
wbb1395
这个作者很懒,什么都没留下…
展开
-
golang builder,buffer,+的对比
使用buffer或是builder来拼接字符串,会比使用+或+=快 func BenchmarkBuffer(b *testing.B) { text := "text" buffer := bytes.Buffer{} b.ResetTimer() for i := 0; i < b.N; i++ { buffer.WriteString(text) } } func BenchmarkBuilder(b *testing.B) { text := "text" builder原创 2021-11-24 18:51:59 · 438 阅读 · 0 评论 -
golang srpint和itoa对比
数字转换成字符串,使用 strconv.Itoa() 比 fmt.Sprintf() 要快 func BenchmarkItoa(b *testing.B) { number := 1234567890 b.ResetTimer() for i := 0; i < b.N; i++ { strconv.Itoa(number) } } func BenchmarkSprint(b *testing.B) { number := 1234567890 b.ResetTimer()原创 2021-10-19 15:23:18 · 251 阅读 · 0 评论 -
golang defer总结
A "defer" statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function executed areturn statement, reached the end of itsfunction body, or because the corresponding goro...转载 2020-05-27 18:13:34 · 116 阅读 · 0 评论 -
golang 构造函数
package main import ( "fmt" ) type test struct { a int b string } func newTest1(a int, b string) *test { t := new(test) t.a = a t.b = b return t } func newTest2(a int, b string) *test { return &test{a, b} } type testConstruct func(*test) .原创 2020-05-14 15:48:28 · 899 阅读 · 0 评论