2 ms·
You're micro-optimizing the wrong thing, most of the time taken in C# is in the .Split(' ', StringSplitOptions.RemoveEmptyEntries) (which is UNICODE instead of
by Someone1234 6y ago
You're micro-optimizing the wrong thing, most of the time taken in C# is in the .Split(' ', StringSplitOptions.RemoveEmptyEntries) (which is UNICODE instead of ASCII as in other languages by the way) and also Console.ReadLine().
C# supports non-allocating splitting via the Span / ReadOnlySpan see this article about this very question:
https://www.meziantou.net/split-a-string-into-lines-without-allocation.htm https://www.meziantou.net/split-a-string-into-lines-without-...
You can also use the Win32 APIs to more efficiently hook the console input:
https://stackoverflow.com/questions/33342340/fast-reading-of-console-input https://stackoverflow.com/questions/33342340/fast-reading-of...
You can change foreach to for or whatever, but after you deal with the major program's bottlenecks.
- pjmlp 6y agoSurely, I haven't bothered to list everything.