Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ConsoleApplication2 {
- class Program {
- static string Concat(string s) {
- return "for" + s + "bar" + s + "0123456789" + s + "01234567890123456789" + s + "01234567890123456789";
- }
- static string Builder(string s) {
- StringBuilder sb = new StringBuilder();
- sb.Append("for");
- sb.Append(s);
- sb.Append("bar");
- sb.Append(s);
- sb.Append("0123456789");
- sb.Append(s);
- sb.Append("01234567890123456789");
- sb.Append(s);
- sb.Append("01234567890123456789");
- return sb.ToString();
- }
- static string Format(string s) {
- return string.Format("for{0}bar{1}0123456789{2}01234567890123456789{3}01234567890123456789", s, s, s, s);
- }
- static void Test(Func<string, string> f) {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- for (int m = 0; m < 1000000; m++) {
- var s = f("blablabla");
- }
- sw.Stop();
- Console.WriteLine("{0}: {1} ms", f.GetType().Name, sw.ElapsedMilliseconds);
- }
- static void Main(string[] args) {
- foreach (var method in new Func<string, string>[] { Concat, Builder, Format }) {
- Test(method);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement