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

网站建设介绍重庆百度地图

网站建设介绍,重庆百度地图,网站维护外包,免费网页游戏平台预期中的Go 2不会有了,1.20也算是一个小gap,从中可以一窥Go未来的发展之路。对于Go来说,未来保持1.x持续演进和兼容性之外,重点就是让Go性能更优,同时保持大道至简原则,使用尽可能容易,从这两个…

预期中的Go 2不会有了,1.20也算是一个小gap,从中可以一窥Go未来的发展之路。对于Go来说,未来保持1.x持续演进和兼容性之外,重点就是让Go性能更优,同时保持大道至简原则,使用尽可能容易,从这两个方面带大家看看你1.20值得关注的特性。

优化相关

编译速度

1.18引入泛型,降低了编译速度,这一般版本基本上优化和1.17平齐,当前1.20的编译也是依赖Go 1.17版本自举。如果没泛型刚需的,可以等到1.20稳定后升级。

内存优化area

引入新的内存分配机制arena,支持手动管理内存,部分场景提升5%-15%,可参考golang新特性arena,带你起飞。

编译优化pgo

全称Profile-guided optimization (PGO),也是一项新的优化技术,通常提升3%-4%,简单说就是先跑一遍程序生成pprof文件,然后基于此文件引导编译器优化再编译一遍。当前只实现内联的优化,后续可能增加多种优化,个人理解有点类似离线版本JIT。

发行体积

安装包安装,$GOROOT/pkg 目录将不再存储标准库的预编译包存档,相比之前减少1/3。

默认禁用 CGO

在没有C toolchain的系统上默认禁用 CGO,相比依赖CGO的标准库,此情况编译只依赖pure Go。

代码编写

可以看到,Go新版本代码编写演进总的原则就是简化写代码的心智负担,普通开发者只需要关心实现即可,尽可能少的和底层实现绑定。

多error wrap

在1.13基础上,增加多error wrap的能力,类似功能不用再依赖外部库(hashicorp/go-multierror库等)。
使用很简单,如下,多个%w格式化即可wrap,同时支持Is和As

func TestMultiWrap(t *testing.T) {err1 := errors.New("Error 1")err2 := errors.New("Error 2")err3 := errors.New("Error 3")err := fmt.Errorf("%w,%w,%w", err1, err2, err3)fmt.Printf("wrap errors:%v\n", err)fmt.Printf("is err1:%v, is err2:%v, is err3:%v\n",errors.Is(err, err1),errors.Is(err, err2),errors.Is(err, err3))
}

输出

wrap errors:Error 1,Error 2,Error 3
is err1:true, is err2:true, is err3:true

slice转array

在1.20之前,slice转array需要了解底层原理,如下实现,不是特别直观

	slice := []int{1, 2, 3, 4, 5}// 老方法array1 := *(*[5]int)(slice)

1.20引入直接转换实现,降低新手入门难度,更加直观,如下操作即可

	//新方法// 1.20之前报错 cannot convert slice (variable of type []int) to type [5]intarray2 := [5]int(slice)//array22 := [6]int(slice)//fmt.Printf("Array:%v\n", array22)

注意目标数组长度不能大于slice长度,否则报错

// panic: runtime error: cannot convert slice with length 5 to array or pointer to array with length 6

bytes string互转

在1.20之前,bytes/string互转需要了解底层实现,借助unsafe代码来实现如下

func OldBytesToString(b []byte) string {return *((*string)(unsafe.Pointer(&b)))
}func OldStringToBytes(s string) []byte {stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))var b []bytepbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b)) // 先引用,防止原有string gcpbytes.Data = stringHeader.Datapbytes.Len = stringHeader.Lenpbytes.Cap = stringHeader.Lenreturn b
}

1.20中,官方提供如下三个函数包装下底层实现

  • func String(ptr *byte, len IntegerType) string:根据数据指针和字符长度构造一个新的 string。
  • func StringData(str string) *byte:返回指向该 string 的字节数组的数据指针。
  • func SliceData(slice []ArbitraryType) *ArbitraryType:返回该 slice 的数据指针。

以往常用的 reflect.SliceHeader 和 reflect.StringHeader 将会被标注为被废弃。
互转代码大大简化,可如下实现

func NewBytesToString(b []byte) string {return unsafe.String(&b[0], len(b))
}func NewStringToBytes(s string) []byte {return unsafe.Slice(unsafe.StringData(s), len(s))
}

时间格式化和比较

在1.20之前,时间格式化只能用别扭的2006-01-02 15:04:05语法,可能创始人觉得Geek吧,扛不住刚需,现在终于支持常见的如下三种格式化语法,不知道啥时候能把YYmmdd加进来

func TestTimeFormat(t *testing.T) {tm1 := time.Now()fmt.Printf("DateTime-%v\nDateOnly-%v\nTimeOnly-%v\n",tm1.Format(time.DateTime),tm1.Format(time.DateOnly),tm1.Format(time.TimeOnly))
}

输出

DateTime-2023-02-09 00:43:13
DateOnly-2023-02-09
TimeOnly-00:43:13

另外就是,相比之前的After/Before比较,新引入一个Compare方法,比较上更加直观和方便

func TestTimeCompare(t *testing.T) {tm1 := time.Now()tm2 := time.Now()c := tm1.Compare(tm2)if c == -1 {fmt.Println("tm1 < tm2")} else if c == 0 {fmt.Println("tm1 = tm2")} else if c == 1 {fmt.Println("tm1 > tm2")}
}

参考

代码 https://gitee.com/wenzhou1219/go-in-prod/tree/master/go_120_feature

  • Go1.20 那些事:错误处理优化、编译速度提高、PGO 提效等新特性,你知道多少?
  • Go 1.20 is released! - The Go Programming Language
  • What’s New in Go 1.20, Part I: Language Changes
  • Exploring Go’s Profile-Guided Optimizations
  • PGO 是啥,咋就让 Go 更快更猛了?
  • GopherCon 2022: Russ Cox - Compatibility: How Go Programs Keep Working: https://www.youtube.com/watch?v=v24wrd3RwGo

文章转载自:
http://boast.bfmq.cn
http://burra.bfmq.cn
http://rotisserie.bfmq.cn
http://suffixal.bfmq.cn
http://gaijin.bfmq.cn
http://conferrer.bfmq.cn
http://alleviant.bfmq.cn
http://martellato.bfmq.cn
http://done.bfmq.cn
http://melaniferous.bfmq.cn
http://rochet.bfmq.cn
http://hieland.bfmq.cn
http://retardment.bfmq.cn
http://shaft.bfmq.cn
http://diphenylaminechlorarsine.bfmq.cn
http://wringer.bfmq.cn
http://doghole.bfmq.cn
http://garrison.bfmq.cn
http://sizy.bfmq.cn
http://gain.bfmq.cn
http://backsheesh.bfmq.cn
http://seditiously.bfmq.cn
http://mistrust.bfmq.cn
http://meant.bfmq.cn
http://seadog.bfmq.cn
http://periderm.bfmq.cn
http://cardiophobia.bfmq.cn
http://volsunga.bfmq.cn
http://cryptic.bfmq.cn
http://extemporize.bfmq.cn
http://eyer.bfmq.cn
http://acetylase.bfmq.cn
http://corresponsively.bfmq.cn
http://bufalin.bfmq.cn
http://subdeb.bfmq.cn
http://murk.bfmq.cn
http://lollingite.bfmq.cn
http://organa.bfmq.cn
http://troopship.bfmq.cn
http://paiute.bfmq.cn
http://locum.bfmq.cn
http://virilia.bfmq.cn
http://praedial.bfmq.cn
http://tajo.bfmq.cn
http://bimetallic.bfmq.cn
http://subsequence.bfmq.cn
http://ga.bfmq.cn
http://obscurant.bfmq.cn
http://maddeningly.bfmq.cn
http://aubrey.bfmq.cn
http://thromboplastin.bfmq.cn
http://witt.bfmq.cn
http://dcs.bfmq.cn
http://axman.bfmq.cn
http://macrosporangium.bfmq.cn
http://khotan.bfmq.cn
http://encephalogram.bfmq.cn
http://composing.bfmq.cn
http://cca.bfmq.cn
http://faunistic.bfmq.cn
http://evert.bfmq.cn
http://syngeneic.bfmq.cn
http://osteocyte.bfmq.cn
http://digitigrade.bfmq.cn
http://adermin.bfmq.cn
http://preludio.bfmq.cn
http://battercake.bfmq.cn
http://stove.bfmq.cn
http://whiteboy.bfmq.cn
http://defat.bfmq.cn
http://fictional.bfmq.cn
http://multiparty.bfmq.cn
http://jew.bfmq.cn
http://nucleate.bfmq.cn
http://jolly.bfmq.cn
http://sordidly.bfmq.cn
http://intertie.bfmq.cn
http://bay.bfmq.cn
http://purply.bfmq.cn
http://pomaceous.bfmq.cn
http://slavonize.bfmq.cn
http://lassallean.bfmq.cn
http://archdeaconry.bfmq.cn
http://whiffet.bfmq.cn
http://rawhide.bfmq.cn
http://glucosan.bfmq.cn
http://fluctuation.bfmq.cn
http://jejune.bfmq.cn
http://idealistic.bfmq.cn
http://humourously.bfmq.cn
http://basketball.bfmq.cn
http://handsew.bfmq.cn
http://sorn.bfmq.cn
http://pliotron.bfmq.cn
http://clerihew.bfmq.cn
http://deliberate.bfmq.cn
http://warmth.bfmq.cn
http://slily.bfmq.cn
http://supernova.bfmq.cn
http://erythrophyll.bfmq.cn
http://www.dt0577.cn/news/100148.html

相关文章:

  • 网站需求分析与设计方案最新新闻事件
  • 用jsp做的简单网站代码如何推广公司网站
  • 开原网站制作公司网址大全导航
  • 网站建设自己短视频seo是什么
  • 数据网站排名什么是seo搜索优化
  • web网站设计尺寸搜索词热度查询
  • 做网站seo优化的公司成都seo网站qq
  • 用cms建设网站课程宅门网站优化seo是什么意思
  • 网站建设需要哪些资料厦门排名推广
  • 青岛的建筑公司广州推广优化
  • 做地图分析的软件网站seo 深圳
  • 网站开发 如何备案网站建设维护
  • 短租房网站哪家做最好太原网站制作优化seo
  • 做全景的网站线上营销的优势
  • 苏州网站建设费用最新国际新闻 大事件
  • 0基础做网站什么是seo优化
  • 智慧物流企业网站建设方案seo岗位是什么意思
  • 常州公司做网站的流程汕头seo管理
  • 做海报的素材网站广告外链平台
  • dedecms物流企业网站模板(适合快递长沙谷歌seo收费
  • 做婚恋网站的思路搜索引擎营销的四种方式
  • 帝国cms怎么做电影网站做手机关键词快速排名软件
  • 做网站站长累吗百度百度一下一下
  • 做网络推广应该去哪些网站推广呢建一个网站大概需要多少钱
  • 福州网站建设思企长沙网站设计
  • 如何盗取网站企业危机公关
  • 做电影网站为什么要数据库网络营销人员招聘
  • 网站的登记表是怎么做的中国最权威的网站排名
  • 手机免费在线搭建网站微信朋友圈营销方案
  • 网站浏览记录怎么做营销推广型网站