public void SerializerGeneration() { var tester = new FirstCallTester(Console.Out); tester.Start(); var msg = new Messages(); tester.Stop(); tester.Start(); CreateProto(); tester.Stop(); tester.Start(); CreateProto(); tester.Stop(); tester.Report(); var reportwatch = new Reportwatch(); reportwatch.Start("Protobuf"); var proto = ProtoBuf.Meta.TypeModel.Create(); proto.Add(typeof(UserInfo), true); proto.CompileInPlace(); reportwatch.Stop("Protobuf"); reportwatch.Start("Protobuf serialize"); proto.Serialize(new MemoryStream(), CreateObj()); reportwatch.Stop("Protobuf serialize"); reportwatch.Start("Protobuf serialize 2"); proto.Serialize(new MemoryStream(), CreateObj()); reportwatch.Stop("Protobuf serialize 2"); reportwatch.Start("DataContractSerializer ctor"); DataContractSerializer xml = new DataContractSerializer(typeof(UserInfo)); reportwatch.Stop("DataContractSerializer ctor"); reportwatch.Start("DataContractSerializer serialize"); xml.WriteObject(new MemoryStream(), CreateObj()); reportwatch.Stop("DataContractSerializer serialize"); reportwatch.Start("DataContractSerializer serialize 2"); xml.WriteObject(new MemoryStream(), CreateObj()); reportwatch.Stop("DataContractSerializer serialize 2"); reportwatch.Report("Protobuf"); reportwatch.Report("Protobuf serialize"); reportwatch.Report("Protobuf serialize 2"); reportwatch.Report("DataContractSerializer ctor"); reportwatch.Report("DataContractSerializer serialize"); reportwatch.Report("DataContractSerializer serialize 2"); Assert.IsTrue(reportwatch.GetTime(new Regex("(Protobuf)")) <= reportwatch.GetTime(new Regex("(DataContractSerializer)"))); }
private static void Main(string[] args) { req_builder builder = req_bytes; resp_builder br = resp_bytes; makeRequest call = makePipeRequest; for (int i = 0; i < args.Length; i++) { string o = args[i]; if (o == "-m") { string s = args[i + 1]; makeRequest makeWindowsMessageRequest = null; makeRequest makeSharedMemoryRequest = null; switch (s) { case "pipes": call = makePipeRequest; break; case "messaging": call = makeWindowsMessageRequest; break; case "rpc": call = makeRpcRequest; break; case "wcf": call = makeWcfRequest; break; default: call = makeSharedMemoryRequest; break; } } if (o == "-d") { string s = args[i + 1]; req_builder req_msg = null; builder = s == "bytes" ? req_bytes : (s == "object" ? req_obj : req_msg); resp_builder resp_msg = null; br = s == "bytes" ? resp_bytes : (s == "object" ? resp_obj : resp_msg); } if (o == "-r") { reuse = true; } if (o == "-o") { oneway = true; } } if (reuse) { if (call == makePipeRequest) { while (!WaitNamedPipe(pipe_name, 1)) { } } if (call == makeRpcRequest) { init_rpc(); } if (call == makeWcfRequest) { init_wcf(); } } byte[] req; uint real_size = 0; byte[] response; uint resp_size = 0; if (!oneway) { init_reqs(req_size100, 5000, 10); init_reqs(req_size50, 2500, 10); init_reqs(req_size10, 500, 10); init_reqs(req_size1, 50, 10); init_reqs(req_size0_1, 5, 10); } builder(req_size100, out req, out real_size); for (int i = 0; i < 5; i++) { call(req_size100, builder, br, out response, out resp_size); } var sw = new Reportwatch(); sw.Lang = ReportwatchLangs.Markdown; sw.SetMode("REAL_TIME"); Console.WriteLine("Client started"); var msr100 = "Client process requests ~100kb and gets ~1000kb response of server process"; var msr50 = "Client process requests ~50kb and gets ~500kb response of server process"; var msr10 = "Client process requests ~10kb and gets ~100kb response of server process"; var msr1 = "Client process requests ~1kb and gets ~10kb response of server process"; var msr0_1 = "Client process requests ~0.1kb and gets ~1kb response of server process"; builder(req_size100, out req, out real_size); Console.WriteLine("Request size :" + real_size / kb + " kb"); for (int i = 0; i < 5; i++) { sw.Start(msr100); call(req_size100, builder, br, out response, out resp_size); sw.Stop(msr100); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size50, out req, out real_size); Console.WriteLine("Request size :" + real_size / kb + " kb"); for (int i = 0; i < 10; i++) { sw.Start(msr50); call(req_size50, builder, br, out response, out resp_size); sw.Stop(msr50); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size10, out req, out real_size); Console.WriteLine("Message size :" + real_size / kb + " kb"); for (int i = 0; i < 50; i++) { sw.Start(msr10); call(req_size10, builder, br, out response, out resp_size); sw.Stop(msr10); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size1, out req, out real_size); Console.WriteLine("Message size :" + real_size + " bytes"); for (int i = 0; i < 500; i++) { //Sleep(1); //BUG: sometimes hangs here when pipes used.... sw.Start(msr1); call(req_size1, builder, br, out response, out resp_size); sw.Stop(msr1); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size0_1, out req, out real_size); Console.WriteLine("Message size :" + real_size + " bytes"); for (int i = 0; i < 1000; i++) {//BUG: server of shared memory crashes if make number of 10000 //Sleep(1); //BUG: sometimes hangs here when pipes used.... sw.Start(msr0_1); call(req_size0_1, builder, br, out response, out resp_size); sw.Stop(msr0_1); } Console.WriteLine("Response size was :" + resp_size + " bytes"); builder(req_size100, out req, out real_size); Console.WriteLine("Request size :" + real_size / kb + " kb"); for (int i = 0; i < 5; i++) { sw.Start(msr100); call(req_size100, builder, br, out response, out resp_size); sw.Stop(msr100); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size50, out req, out real_size); Console.WriteLine("Request size :" + real_size / kb + " kb"); for (int i = 0; i < 10; i++) { sw.Start(msr50); call(req_size50, builder, br, out response, out resp_size); sw.Stop(msr50); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size10, out req, out real_size); Console.WriteLine("Message size :" + real_size / kb + " kb"); for (int i = 0; i < 50; i++) { sw.Start(msr10); call(req_size10, builder, br, out response, out resp_size); sw.Stop(msr10); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size1, out req, out real_size); Console.WriteLine("Message size :" + real_size + " bytes"); for (int i = 0; i < 500; i++) { //Sleep(1); //BUG: sometimes hangs here when pipes used.... sw.Start(msr1); call(req_size1, builder, br, out response, out resp_size); sw.Stop(msr1); } Console.WriteLine("Response size was :" + resp_size / kb + " kb"); builder(req_size0_1, out req, out real_size); Console.WriteLine("Message size :" + real_size + " bytes"); for (int i = 0; i < 1000; i++) {//BUG: server of shared memory crashes if make number of 10000 //Sleep(1); //BUG: sometimes hangs here when pipes used.... sw.Start(msr0_1); call(req_size0_1, builder, br, out response, out resp_size); sw.Stop(msr0_1); } Console.WriteLine("Response size was :" + resp_size + " bytes"); //TODO: make assertion of response sw.Report(msr100); sw.Report(msr50); sw.Report(msr10); sw.Report(msr1); sw.Report(msr0_1); Console.ReadKey(); }