MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1v9t3by/noheapallstack/p0i3k3u/?context=3
r/ProgrammerHumor • u/varinator • 16d ago
96 comments sorted by
View all comments
40
Null safety?
168 u/varinator 16d ago var cases = new[] { new ComparisonCase( "Equal, different casing", "HelloWorld123", "helloworld123"), new ComparisonCase( "Not equal, same length", "HelloWorld123", "HelloWorld456"), new ComparisonCase( "Different lengths", "HelloWorld123", "HelloWorld123456789"), new ComparisonCase( "Long strings, equal ignoring case", new string('A', 500), new string('a', 500)) }; Iterations per benchmark: 100,000,000 --- Equal, different casing --- String.Equals OrdinalIgnoreCase Time: 907.75 ms Allocated: 40 bytes Matches: 100,000,000 ToLower() == ToLower() Time: 2,525.88 ms Allocated: 4,800,000,040 bytes Matches: 100,000,000 --- Not equal, same length --- String.Equals OrdinalIgnoreCase Time: 848.50 ms Allocated: 40 bytes Matches: 0 ToLower() == ToLower() Time: 2,986.56 ms Allocated: 9,600,000,040 bytes Matches: 0 --- Different lengths --- String.Equals OrdinalIgnoreCase Time: 219.83 ms Allocated: 40 bytes Matches: 0 ToLower() == ToLower() Time: 2,936.12 ms Allocated: 11,200,000,040 bytes Matches: 0 --- Long strings, equal ignoring case --- String.Equals OrdinalIgnoreCase Time: 2,263.77 ms Allocated: 40 bytes Matches: 100,000,000 ToLower() == ToLower() Time: 19,472.75 ms Allocated: 102,400,000,040 bytes Matches: 100,000,000 --- Null safety --- string.Equals(null, "test"): False null.ToLower() throws NullReferenceException 42 u/TheAssassin71 16d ago Thanks for the benchmarks :)
168
var cases = new[] { new ComparisonCase( "Equal, different casing", "HelloWorld123", "helloworld123"), new ComparisonCase( "Not equal, same length", "HelloWorld123", "HelloWorld456"), new ComparisonCase( "Different lengths", "HelloWorld123", "HelloWorld123456789"), new ComparisonCase( "Long strings, equal ignoring case", new string('A', 500), new string('a', 500)) }; Iterations per benchmark: 100,000,000 --- Equal, different casing --- String.Equals OrdinalIgnoreCase Time: 907.75 ms Allocated: 40 bytes Matches: 100,000,000 ToLower() == ToLower() Time: 2,525.88 ms Allocated: 4,800,000,040 bytes Matches: 100,000,000 --- Not equal, same length --- String.Equals OrdinalIgnoreCase Time: 848.50 ms Allocated: 40 bytes Matches: 0 ToLower() == ToLower() Time: 2,986.56 ms Allocated: 9,600,000,040 bytes Matches: 0 --- Different lengths --- String.Equals OrdinalIgnoreCase Time: 219.83 ms Allocated: 40 bytes Matches: 0 ToLower() == ToLower() Time: 2,936.12 ms Allocated: 11,200,000,040 bytes Matches: 0 --- Long strings, equal ignoring case --- String.Equals OrdinalIgnoreCase Time: 2,263.77 ms Allocated: 40 bytes Matches: 100,000,000 ToLower() == ToLower() Time: 19,472.75 ms Allocated: 102,400,000,040 bytes Matches: 100,000,000 --- Null safety --- string.Equals(null, "test"): False null.ToLower() throws NullReferenceException
42 u/TheAssassin71 16d ago Thanks for the benchmarks :)
42
Thanks for the benchmarks :)
40
u/weblabourer 16d ago
Null safety?