public static void Run() { CodeTimer.Initialize(); var type = typeof(MessageTest <CmdTest>); var ctor = type.GetConstructors()[2]; ObjectActivator <object> createdActivator = ActivatorHelper.GetActivator <object>(ctor); var input = new CmdTest(); var header = new MessageHeaderTest(); object tmpObj = null; var count = 1000000; CodeTimer.Time("new instance", count, () => { tmpObj = new MessageTest <CmdTest>(input, header); }); CodeTimer.Time("exp tree", count, () => { tmpObj = createdActivator(input, header); }); CodeTimer.Time("Activator.CreateInstance", count, () => { tmpObj = Activator.CreateInstance(type, input, header); }); CodeTimer.Time("exp tree2", count, () => { tmpObj = ActivatorHelper.CreateInstance(type, input, header); }); }
public void ClosurePerformanceTest() { var o = new Closure(); var r = new Random((int)DateTime.Now.ToBinary()); var iteration = 100; o.Sample = new List <int>(iteration); for (int i = 0; i < iteration; i++) { o.Sample.Add(r.Next(0, 1024)); } //准备一个有1k元素的集合,遍历,测试闭包性能 Parallel.For(0, 1024, i => o.Content.Add(i)); CodeTimer.Initialize(); CodeTimer.Time("闭包方式测试", 100000, 100, 10, (samples) => { samples.UseClosure(); return(string.Empty); }, o); //o.UseClosure() CodeTimer.Time("迭代方式测试", 100000, 100, 10, (samples) => { samples.NoClosure(); return(string.Empty); }, o); }
static void Main(string[] args) { User u = new User(); CodeTimer.Initialize(); CodeTimer.Time("MethodInfo", 1000000, () => GetName2(u)); CodeTimer.Time("dynamic", 1000000, () => GetName3(u)); CodeTimer.Time("Literacy", 1000000, () => GetName(u)); var tester = new TesterBase[] { new LinqTester(), new CreateDelegateTester(), new LiteracyTester(), }; foreach (var t in tester) { t.TestCount = 1000000; t.State = new User() { Name = "blqw1" }; t.Start(); } }
static void Main(string[] args) { var fileName = "source4compress.txt"; var str = File.ReadAllText(fileName); Console.WriteLine("SourceFileSize\t" + str.Length.ToString("N0")); var snappybin = SnappyCompress(str); var lz4bin = LZ4Compress(str); var gzipbin = GZipCompress(str); var zstdbin = ZstdCompress(str, false, true); #region codetimer 测试代码性能 CodeTimer.Initialize(); var count = 100; CodeTimer.Time("SnappyCompress\t" + snappybin.Length.ToString("N0"), count, () => { SnappyCompress(str); }); CodeTimer.Time("LZ4Compress\t" + lz4bin.Length.ToString("N0"), count, () => { LZ4Compress(str); }); CodeTimer.Time("ZstdCompress\t" + zstdbin.Length.ToString("N0"), count, () => { ZstdCompress(str, false, true); }); CodeTimer.Time("GZipCompress\t" + gzipbin.Length.ToString("N0"), count, () => { GZipCompress(str); }); CodeTimer.Time("SnappyUnCompress", count, () => { SnappyUnCompress(snappybin); }); CodeTimer.Time("LZ4UnCompress", count, () => { LZ4UnCompress(lz4bin); }); CodeTimer.Time("ZstdUnCompress", count, () => { ZstdUnCompress(zstdbin); }); CodeTimer.Time("GZipUnCompress", count, () => { GZipUnCompress(gzipbin); }); #endregion Console.Read(); }
public void Test_Create() { CodeTimer.Initialize(); CodeTimer.CodeExecuteTime(() => { var result = TimestampIdGenerator.Current.Create(); Output.WriteLine(result.ToString()); }); }
//测试QuickJsonBuilder性能 public static void TestQuickJsonBuilder() { CodeTimer.Initialize(); object obj = TestObject; obj.ToJsonString(); CodeTimer.Time(N("QuickJsonBuilder序列化"), TestCount, () => { obj.ToJsonString(); }); }
public void CreateObjWithReflector() { CodeTimer.Initialize(); for (int count = 10000; count < 100000000; count *= 10) { CodeTimer.Time("直接创建对象", count, () => new Entity()); CodeTimer.Time("反射创建对象", count, () => Activator.CreateInstance(typeof(Entity))); } }
public static void TestJavaScriptSerializer() { CodeTimer.Initialize(); object obj = TestObject; new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj); CodeTimer.Time(N("JavaScriptSerializer序列化"), TestCount, () => { new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj); }); }
//测试Crylw.Json性能 public static void TestCrylwJson() { CodeTimer.Initialize(); object obj = TestObject; Crylw.Json.Json.ToString(obj); CodeTimer.Time(N("Crylw.Json序列化"), TestCount, () => { Crylw.Json.Json.ToString(obj); }); }
public static void TestNewtonsoftJson() { CodeTimer.Initialize(); object obj = TestObject; Newtonsoft.Json.JsonConvert.SerializeObject(obj); CodeTimer.Time(N("NewtonsoftJson序列化"), TestCount, () => { Newtonsoft.Json.JsonConvert.SerializeObject(obj); }); }
//测试QuickJsonBuilder性能 public static void TestQuickJsonBuilder <T>() { TestObject = Activator.CreateInstance <T>(); CodeTimer.Initialize(); var jsonString = TestJsonString; var obj = new JsonParser().ToObject(typeof(T), jsonString); CodeTimer.Time(N("QuickJsonBuilder反序列化"), TestCount, () => { new JsonParser().ToObject(typeof(T), jsonString); }); }
//测试FastJson性能 public static void TestFastJson <T>() { TestObject = Activator.CreateInstance <T>(); CodeTimer.Initialize(); CodeTimer.Initialize(); var jsonString = TestJsonString; fastJSON.JSON.Instance.ToObject <T>(jsonString); CodeTimer.Time(N("FastJson反序列化"), TestCount, () => { fastJSON.JSON.Instance.ToObject <T>(jsonString); }); }
public void Test_Create_10000() { CodeTimer.Initialize(); CodeTimer.CodeExecuteTime(() => { for (int i = 0; i < 10000; i++) { var result = ObjectIdGenerator.Current.Create(); Output.WriteLine(result.ToString()); } }); }
public void CodeTimerAll() { CodeTimer.Initialize(); int times = 1000; string s = ""; CodeTimer.Time("String Concat", times, () => { s += "a"; }); StringBuilder sb = new StringBuilder(); CodeTimer.Time("StringBuilder", times, () => { sb.Append("a"); }); }
public void Time_Test() { CodeTimer.Initialize(); CodeTimer.Time("name", 10000, () => { int sum = 0; for (int i = 1; i <= 100; i++) { sum++; } Console.WriteLine(sum); }); }
public void Start() { Console.WriteLine($" 准备测试[{Name}]"); var watch = new Stopwatch(); watch.Start(); Initialize(); watch.Stop(); Console.WriteLine($"初始化用时:{watch.Elapsed.TotalMilliseconds} ms"); CodeTimer.Initialize(); CodeTimer.Time(Name, TestCount, Testing); Console.WriteLine(); }
public void TestForCodeTimer() { var CachedProcessPriorityClass = Process.GetCurrentProcess().PriorityClass; var CachedThreadPriority = Thread.CurrentThread.Priority; using (var timer = new CodeTimer()) { timer.Initialize(); var result = timer.Time(1, () => { }); } Assert.AreEqual(CachedProcessPriorityClass, Process.GetCurrentProcess().PriorityClass); Assert.AreEqual(CachedThreadPriority, Thread.CurrentThread.Priority); }
public void StringFormatTest() { CodeTimer.Initialize(); var i = 1024; CodeTimer.Time( String.Format("StringFormat ({0})", i), 10000, () => DealWithString.StringFormat(i)); CodeTimer.Time( String.Format("StringBuilderFormat ({0})", i), 10000, () => DealWithString.StringBuilderFormat(i)); }
public void Time_Test() { CodeTimer.Initialize(); string output = CodeTimer.Time("name", 10000, () => { int sum = 0; for (int i = 1; i <= 100; i++) { sum++; } sum.ShouldBe(100); }); output.ShouldContain("CPU Cycles"); output.ShouldContain("ms"); }
//测试JayrockJson性能 public static void TestJayrockJson() { CodeTimer.Initialize(); object obj = TestObject; { var writer = new Jayrock.Json.JsonTextWriter(); Jayrock.Json.Conversion.JsonConvert.Export(obj, writer); writer.ToString(); } CodeTimer.Time(N("JayrockJson序列化"), TestCount, () => { var writer = new Jayrock.Json.JsonTextWriter(); Jayrock.Json.Conversion.JsonConvert.Export(obj, writer); writer.ToString(); }); }
static void Main(string[] args) { var rand = new Random(); CodeTimer timer = new CodeTimer(); timer.Initialize(); EmptyModel model = new EmptyModel(); Console.WriteLine(model == new EmptyModel()); Console.WriteLine(model.Equals(1)); Console.WriteLine("Hello World"); Console.ReadKey(true); }
static void Main(string[] args) { int[] data = new int[] { 3, 2, 4, 1, 5 }; int[] data1 = new int[] { 3, 2, 4, 1, 5 }; CodeTimer.Initialize(); SelectSort(data); //InsertSort(data); //BubbleSort(data); //ShellSort(data1); Console.ReadKey(); }
static void Main(string[] args) { CodeTimer.Initialize(); //CodeTimer.Time("a", 4, () => { // using (var conn = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True")) // using (var cmd = conn.CreateCommand()) // { // cmd.CommandText = "select count(1) from sys.objects"; // conn.Open(); // } //}); //using (var conn = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True")) //{ // conn.Open(); // CodeTimer.Time("b", 4, () => { // using (var cmd = conn.CreateCommand()) // { // cmd.CommandText = "select count(1) from sys.objects"; // } // }); //} //return; //// FQL.CurrentFQLProvider = FQL.SqlServer; //设定默认FQL格式化机制,因为系统默认就是SqlServer,所以可以省略 //var keyword = "sys"; ////var r = FQL.Format(FQL.SqlServer, sql, "sys"); //也可以在方法中设定格式化机制 //var r = FQL.Format(SqlServerFQL.Instance,"select count(1) from sys.objects where name like '%' + {0} + '%'", keyword); //using (var conn = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True")) //using (var cmd = conn.CreateCommand()) //{ // cmd.CommandText = r.CommandText; //设置CommandText // cmd.Parameters.AddRange(r.DbParameters);//设定Parameters // conn.Open(); // Console.WriteLine(cmd.ExecuteScalar()); //} //OutDemo(); //SearchCountDemo2("a", "S", null); }
public void StringConcatTest() { CodeTimer.Initialize(); for (int i = 2; i <= 1024; i *= 2) { CodeTimer.Time( String.Format("Normal Concat ({0})", i), 10000, () => DealWithString.NormalConcat(i)); CodeTimer.Time( String.Format("StringBuilder ({0})", i), 10000, () => DealWithString.StringBuilder(i)); CodeTimer.Time( String.Format("String.Concat ({0})", i), 10000, () => DealWithString.StringConcat(i)); } }
//测试FastJson性能 public static void TestFastJson() { CodeTimer.Initialize(); object obj = TestObject; JSONParameters p = new JSONParameters(); p.EnableAnonymousTypes = p.IgnoreCaseOnDeserialize = p.ShowReadOnlyProperties = p.UseEscapedUnicode = p.UseExtensions = p.UseFastGuid = p.UseOptimizedDatasetSchema = p.UseUTCDateTime = p.UsingGlobalTypes = false; fastJSON.JSON.Instance.ToJSON(obj, p); CodeTimer.Time(N("FastJson序列化"), TestCount, () => { fastJSON.JSON.Instance.ToJSON(obj, p); }); }
private void Create(long length) { CodeTimer.Initialize(); CodeTimer.CodeExecuteTime(() => { for (int i = 0; i < length; i++) { var result = TimestampIdGenerator.Current.Create(); lock (_lock) { if (_set.Contains(result)) { Output.WriteLine("发现重复项:{0}", result); } else { _set.Add(result); } } } }); }
static void Main(string[] args) { CodeTimer.Initialize(); Console.WriteLine("IOC - Singleton"); // Autofac Singleton RunManager.Start(new AutofacRunner(), RunType.Singleton); // Castle Windsor RunManager.Start(new WindsorRunner(), RunType.Singleton); // Unity RunManager.Start(new UnityRunner(), RunType.Singleton); // Spring.NET RunManager.Start(new SpringRunner(), RunType.Singleton); // StructureMap RunManager.Start(new StructureMapRunner(), RunType.Singleton); // Ninject RunManager.Start(new NinjectRunner(), RunType.Singleton); // NLite RunManager.Start(new NLiteRunner(), RunType.Singleton); Console.WriteLine("==================================="); Console.WriteLine("IOC - Transient"); // Autofac Singleton RunManager.Start(new AutofacRunner(), RunType.Transient); // Castle Windsor RunManager.Start(new WindsorRunner(), RunType.Transient); // Unity RunManager.Start(new UnityRunner(), RunType.Transient); // Spring.NET RunManager.Start(new SpringRunner(), RunType.Transient); // StructureMap RunManager.Start(new StructureMapRunner(), RunType.Transient); // Ninject RunManager.Start(new NinjectRunner(), RunType.Transient); // NLite RunManager.Start(new NLiteRunner(), RunType.Transient); Console.Read(); }
static void Main(string[] args) { var rand = new Random(); CodeTimer timer = new CodeTimer(); timer.Initialize(); DistinctSubseqII instance = new DistinctSubseqII(); Console.WriteLine(instance.Simple("abc")); Console.WriteLine(instance.Simple("aba")); Console.WriteLine(instance.Simple("aaa")); Console.ReadKey(); for (int i = 0; i < 100; i++) { var len = rand.Next(2000) + 1; StringBuilder builder = new StringBuilder(); for (int j = 0; j < len; j++) { builder.Append((char)('a' + rand.Next(26))); } ShowConsole(new Dictionary <string, Func <object> >() { { "str", () => builder }, { "result", () => instance.Simple(builder.ToString()) } }); } Console.WriteLine("Hello World"); Console.ReadKey(true); }
public static void MyClassInitialize(TestContext testContext) { CodeTimer.Initialize(); }
public ObjectIdGeneratorTest(ITestOutputHelper output) : base(output) { CodeTimer.Initialize(); }