The slowest thing there, of course, is Console.WriteLine (). Take the following example:
public void TestCleanSpeed() { var start = DateTime.Now; for (var i = 0; i < 10000; i++) { string[] tests = { "{http://company.com/Services/Types}ModifiedAt", "{http://company.com/Services/Types}CreatedAt" }; foreach (var test in tests) { Console.WriteLine(Clean(test)); } } var end = DateTime.Now; var ts = end - start; Console.WriteLine(ts); }
If you run it as is, it takes almost six seconds. Then remove Console.WriteLine and instead assign var newTest = Clean(test); . In my test, for 10,000 executions, it took less than 0.02 seconds.
Matt grande
source share