Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
.ToCharArray()
instead of .ToArray()
on string
The former is preferable performance-wise. See https://stackoverflow.com/a/37139124
- Loading branch information
7b6be39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I like the pursuit of performance!
The stackoverflow answer is from 2016 and the source codes have changed a lot since .NET 5.
ToCharArray
is absolutely faster. Further speaking, we could import some benchmarks to make perf-improvement more convincing if possible.Also, I suggest that do NOT use LINQ for hot path codes.
Another example is Encode(params int[] numbers), which could be a hot path if users encode multiple numbers.
The following is my benchmarks for .NET 6/7 based on
BenchmarkDotNet
.The source codes are below.