Skip to content

exstrings.Reverse 性能改进 #5

@thinkeridea

Description

@thinkeridea

该方法收集于官网 How to write Go code 中的一个代码片段,因曾经面试遇到这个面试题而留心。

近期回答 Go Forum 中关于 [SOLVED] String size of 20 character 中字符串长度截取使用 []rune 类型与字符串类型转换,期望处理安全的 unicode 字符。

我对此方法提出了性能质疑,编写了基于 utf8.DecodeRuneInString 的计算版本,并做了性能测试 相关回复在这里 发现两个种方法性能差距惊人。

我想到了 go-extend 中的 exstrings.Reverse 方法也是用了类似的类型转换,所以我做了一个小的实验来测试不同实现的性能。

Metadata

Metadata

Assignees

No one assigned

    Labels

    optimizePromote or improve code functionality and performance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions