コード例 #1
0
        private void TestPhotonMapper()
        {
            SpeedComparisonContract contract = CreateSpeedComparisonContract();

            Stopwatch sw = new Stopwatch();

            for (int i = 0; i < WarmupIterations; i++)
            {
                _mapper.ToDictionary(contract);
            }
            sw.Restart();
            for (int i = 0; i < TotalIterations; i++)
            {
                _mapper.ToDictionary(contract);
            }
            sw.Stop();
            Console.WriteLine($"PhotonMapper.ToDictionary: {sw.Elapsed.TotalMilliseconds}ms ({sw.Elapsed.TotalMilliseconds / TotalIterations}ms/iterations)");

            Dictionary <byte, object> parameters = _mapper.ToDictionary(contract);

            for (int i = 0; i < WarmupIterations; i++)
            {
                _mapper.FromDictionary <SpeedComparisonContract>(parameters);
            }
            sw.Restart();
            for (int i = 0; i < TotalIterations; i++)
            {
                _mapper.FromDictionary <SpeedComparisonContract>(parameters);
            }
            Console.WriteLine($"PhotonMapper.FromDictionary: {sw.Elapsed.TotalMilliseconds}ms ({sw.Elapsed.TotalMilliseconds / TotalIterations}ms/iterations)");
            sw.Stop();
        }
コード例 #2
0
        private void RunSimpleContract()
        {
            SimpleContract contract = new SimpleContract
            {
                TestDictionary = new Dictionary <string, string>(),
                Number         = 2,
                Name           = "Horst",
                AnEnum         = ExampleEnum.Example1,
            };

            Dictionary <byte, object> parameters = _photonMapper.ToDictionary(contract);

            SimpleContract newContract = _photonMapper.FromDictionary <SimpleContract>(parameters);

            Console.WriteLine($"----{nameof(SimpleContract)}----");
            Console.WriteLine($"Number: '{newContract.Number}'");
            Console.WriteLine($"Name: '{newContract.Name}'");
            Console.WriteLine($"AnEnum: '{newContract.AnEnum}'");
        }