Created
January 16, 2017 12:51
-
-
Save hagronnestad/84001c6d0a2870aee36206900a398fab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var longString = "This is a long string."; | |
var iterations = 1000000; | |
var timer = new Stopwatch(); | |
"\nTake()".Dump(); | |
timer.Start(); | |
for (int i = 0; i < iterations; i++) { | |
var newString = new string(longString.Take(10).ToArray()); | |
if (i == 0) newString.Dump(); | |
} | |
timer.Stop(); | |
timer.Elapsed.TotalMilliseconds.Dump(); | |
timer.Reset(); | |
"\nSubstring()".Dump(); | |
timer.Start(); | |
for (int i = 0; i < iterations; i++) { | |
var newString = longString.Length < 11 ? longString : longString.Substring(0, 10); | |
if (i == 0) newString.Dump(); | |
} | |
timer.Stop(); | |
timer.Elapsed.TotalMilliseconds.Dump(); | |
timer.Reset(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment