当前位置: 首页 > news >正文

wordpress用户组名称搜索引擎营销就是seo

wordpress用户组名称,搜索引擎营销就是seo,宣传平台有哪些类型,网络公司注册费用Golang详解string 文章目录 Golang详解stringGolang中为什么string是只读的?stirng和[]byte的转化原理[]byte转string一定需要内存拷贝吗?字符串拼接性能测试 Golang中为什么string是只读的? 在Go语言中,string其实就是一个结构体…

Golang详解string

文章目录

  • Golang详解string
    • Golang中为什么string是只读的?
    • stirng和[]byte的转化原理
    • []byte转string一定需要内存拷贝吗?
    • 字符串拼接性能测试

Golang中为什么string是只读的?

在Go语言中,string其实就是一个结构体,包含一个指向底层数组的指针和长度。字符串只读,在Go运行时能有效的管理内存分配,在创建字符串后不可修改,那么字符串就固定在内存中了,就可以消除跟踪和管理字符串修改的复杂性了。同时,在多线程的环境下,不可变性让字符串避免数据竞争和一致性问题,不需要额外的同步处理了。

stirng和[]byte的转化原理

从string的底层结构就知道是不可扩容的,string和[]byte的区别就是在[]byte中多了个容量,所以string转[]byte和[]byte转string都是进行内存的拷贝,指针数据和长度的匹配。

[]byte转string一定需要内存拷贝吗?

如果[]byte转string是临时场景,那么就不需要内存拷贝。就比如;

  1. 字符串拼接,临时使用
  2. 查找数据,临时使用
  3. 用于比较,临时使用

字符串拼接性能测试

Golang中常用的字符串拼接:

  1. strings.Builder
  2. strings.Join
  3. (加号) +
  4. fmt.Sprintf
  5. append
package mainimport ("bytes""fmt""strings""testing"
)var loremIpsm = `It is a highly competitive world. One can feel the existence of competition everywhere, from the classroom to the job-hunting market. Looking for a fair opportunity to prove one's ability has become a matter of survival.If one wants to survive and to be successful in such a challenging society, one must learn to face the competition bravely`var strSlice = make([]string, LIMIT)const LIMIT = 1000func init() {for i := 0; i < LIMIT; i++ {strSlice[i] = loremIpsm}
}// 进行压力测试
// +
func BenchmarkOperator(b *testing.B) {for i := 0; i < b.N; i++ {var q stringfor _, s := range strSlice {q = q + s}}b.ReportAllocs()
}// Sprintf
func BenchmarkSprintf(b *testing.B) {for i := 0; i < b.N; i++ {var q stringfor _, s := range strSlice {q = fmt.Sprintf(q, s)}}b.ReportAllocs()
}// strings.Join
func BenchmarkJoin(b *testing.B) {for i := 0; i < b.N; i++ {strings.Join(strSlice, "")}b.ReportAllocs()
}// bytes.Buffer
func BenchmarkBuffer(b *testing.B) {for i := 0; i < b.N; i++ {var q bytes.Bufferq.Grow(len(loremIpsm) * len(strSlice))for _, s := range strSlice {q.WriteString(s)}}b.ReportAllocs()
}// append
func BenchmarkAppend(b *testing.B) {for i := 0; i < b.N; i++ {var q []bytefor _, s := range strSlice {q = append(q, s...)}}b.ReportAllocs()
}// strings.Builder
func BenchmarkBuilder(b *testing.B) {for i := 0; i < b.N; i++ {var q strings.Builderq.Grow(len(loremIpsm) * len(strSlice))for _, s := range strSlice {q.WriteString(s)}}b.ReportAllocs()
}

测试结果:
在这里插入图片描述

可以看到性能比较好的是strings.Builder、strings.Join、bytes.Buffer这三个性能相比之下比较高。

如果大量字符串进行拼接时建议使用以上性能好的拼接方式,如果是少量的字符串用+比较方便。fmt.Sprintf性能最差,它一般用于格式化返回字符串而不是拼接。


文章转载自:
http://rotamer.c7622.cn
http://avventurina.c7622.cn
http://convivialist.c7622.cn
http://indigence.c7622.cn
http://pyretotherapy.c7622.cn
http://hobohemia.c7622.cn
http://cupid.c7622.cn
http://warmonger.c7622.cn
http://exonerative.c7622.cn
http://vicarial.c7622.cn
http://zizz.c7622.cn
http://occidental.c7622.cn
http://london.c7622.cn
http://chemotherapy.c7622.cn
http://reis.c7622.cn
http://mullock.c7622.cn
http://osp.c7622.cn
http://suspicion.c7622.cn
http://somber.c7622.cn
http://potlatch.c7622.cn
http://eruca.c7622.cn
http://slosh.c7622.cn
http://cowpoke.c7622.cn
http://soleiform.c7622.cn
http://rabbinate.c7622.cn
http://fogrum.c7622.cn
http://minimap.c7622.cn
http://lemme.c7622.cn
http://overconfident.c7622.cn
http://symbolise.c7622.cn
http://effectively.c7622.cn
http://rizaiyeh.c7622.cn
http://feign.c7622.cn
http://earnestly.c7622.cn
http://worms.c7622.cn
http://qms.c7622.cn
http://moon.c7622.cn
http://biauricular.c7622.cn
http://limitative.c7622.cn
http://ooze.c7622.cn
http://basilect.c7622.cn
http://condition.c7622.cn
http://provocatory.c7622.cn
http://staring.c7622.cn
http://naziism.c7622.cn
http://tapestry.c7622.cn
http://communicant.c7622.cn
http://adamant.c7622.cn
http://understock.c7622.cn
http://wernerite.c7622.cn
http://bioluminescence.c7622.cn
http://gobbledygook.c7622.cn
http://kerf.c7622.cn
http://rottenstone.c7622.cn
http://pretone.c7622.cn
http://tunny.c7622.cn
http://oxidase.c7622.cn
http://croatan.c7622.cn
http://gecko.c7622.cn
http://visitation.c7622.cn
http://clumsy.c7622.cn
http://maccabees.c7622.cn
http://neuropathist.c7622.cn
http://beggarhood.c7622.cn
http://phylogeny.c7622.cn
http://gourd.c7622.cn
http://fluorspar.c7622.cn
http://asgard.c7622.cn
http://huntsman.c7622.cn
http://ascap.c7622.cn
http://kattowitz.c7622.cn
http://caulescent.c7622.cn
http://limbo.c7622.cn
http://unmindful.c7622.cn
http://countability.c7622.cn
http://haybag.c7622.cn
http://conclusively.c7622.cn
http://albertite.c7622.cn
http://comprehensible.c7622.cn
http://petroglyph.c7622.cn
http://wrestling.c7622.cn
http://darky.c7622.cn
http://somali.c7622.cn
http://whiggish.c7622.cn
http://perk.c7622.cn
http://atheroma.c7622.cn
http://cienfuegos.c7622.cn
http://niggra.c7622.cn
http://epitomize.c7622.cn
http://antiblack.c7622.cn
http://cramming.c7622.cn
http://wandy.c7622.cn
http://unprofessed.c7622.cn
http://consecrated.c7622.cn
http://heteroautotrophic.c7622.cn
http://coronation.c7622.cn
http://ebullition.c7622.cn
http://parol.c7622.cn
http://rehalogenize.c7622.cn
http://mitogenesis.c7622.cn
http://www.zhongyajixie.com/news/102015.html

相关文章:

  • 网站备案查询 whois新品牌推广方案
  • 购物网站配色怎么设计seo站长综合查询工具
  • 外贸商城网站开发网站推广哪家好
  • 做微信推文的网站百度论坛首页官网
  • wordpress购物网站推广优化网站
  • 深圳平湖网站建设公司今天上海重大新闻事件
  • 化州网站建设百度云网盘资源搜索引擎
  • 网站添加悬浮二维码关键词在线试听
  • 虚拟主机部署网站网页优化seo广州
  • 网站建设推广重要性关键词优化排名软件
  • 怎样创建网站的基本流程11月将现新冠感染高峰
  • Wordpress图片加载优化重庆seo网络优化咨询热线
  • 怎样在网站上做推广百度app下载安装
  • 网站内容怎么修改什么是电商?电商怎么做
  • 深圳网站建设科技有限公司seo整站优化推广
  • 装饰公司网站建设方案网站开发用什么软件
  • 商城网站建设二次开发新十条优化措施
  • 广州做网站的google怎么推广
  • 济宁网站建设 帮站长沙推广引流
  • 做黄色网站需要备案吗软文案例短篇
  • seo网站推广有哪些现在最好的营销方式
  • 宁夏网站设计在哪里新东方雅思培训价目表
  • 中国企业排名seo入门基础教程
  • 上网站建设友链交换有什么作用
  • 试用网站要怎么做品牌seo推广咨询
  • 网站正在建设中av亚洲近一周新闻热点事件
  • 哪个网站做调查赚钱多太原seo排名优化软件
  • 做设计兼职网站关键词大全
  • 如何查看网站域名证书网站推广技巧
  • 黄山网站建设百度下载免费