예제 #1
0
            public void Must_perform_acceptably()
            {
                var sourceFoo = new Foo
                {
                    A       = "SourceA",
                    B       = "SourceB",
                    C       = 1,
                    RefType = new SimpleRefType
                    {
                        Id = Guid.NewGuid()
                    }
                };
                const int numberOfMappings = 10000000;
                var       systemUnderTest  = new DefaultAdapterFactory <Foo, IBar>();
                var       milliseconds     = (long)StopwatchContext.Timed(() =>
                {
                    for (int i = 0; i < numberOfMappings; i++)
                    {
                        IBar bar = systemUnderTest.Create(sourceFoo);
                        // ReSharper disable UnusedVariable
                        string a = bar.A;
                        string b = bar.B;
                        int c    = bar.C;
                        SimpleRefType refType = bar.RefType;
                        // ReSharper restore UnusedVariable
                    }
                }).TotalMilliseconds;

                Console.WriteLine("{0:0.000000000000000}", milliseconds / numberOfMappings);
            }
예제 #2
0
            public void Must_perform_acceptably()
            {
                var sourceFoo = new Foo();
                var targetBar = new Bar();

                sourceFoo.A       = "SourceA";
                sourceFoo.B       = "SourceB";
                sourceFoo.C       = 1;
                sourceFoo.RefType = new SimpleRefType
                {
                    Id = Guid.NewGuid()
                };

                targetBar.likeA       = "WrongA";
                targetBar.likeB       = "WrongB";
                targetBar.likeC       = 0;
                targetBar.likeRefType = null;

                var systemUnderTest = new FooBarMapper();
                var milliseconds    = (long)StopwatchContext.Timed(() =>
                {
                    for (int i = 0; i < 10000000; i++)
                    {
                        systemUnderTest.Map(sourceFoo, targetBar);
                    }
                }).TotalMilliseconds;

                Console.WriteLine(milliseconds);
            }
예제 #3
0
            public void Must_perform_acceptably()
            {
                var sourceFoo = new Foo();
                var targetBar = new Bar();

                sourceFoo.A       = "SourceA";
                sourceFoo.B       = "SourceB";
                sourceFoo.C       = 1;
                sourceFoo.RefType = new SimpleRefType
                {
                    Id = Guid.NewGuid()
                };

                targetBar.A       = "WrongA";
                targetBar.B       = "WrongB";
                targetBar.C       = 0;
                targetBar.RefType = null;

                const int numberOfMappings = 10000000;
                var       systemUnderTest  = new DefaultMapper <Foo, Bar>();
                var       milliseconds     = (long)StopwatchContext.Timed(() =>
                {
                    for (int i = 0; i < numberOfMappings; i++)
                    {
                        systemUnderTest.Map(sourceFoo, targetBar);
                    }
                }).TotalMilliseconds;

                Console.WriteLine("{0:0.000000000000000}", milliseconds / numberOfMappings);
            }
예제 #4
0
            public void Must_perform_acceptably()
            {
                var configuration = new MappingConfiguration <Foo, IFooView>();

                configuration.Map(view => view.Name).From(foo => foo.Name);
                configuration.Map(view => view.Id).From(foo => foo.Id);
                configuration.Map(view => view.Factor).From(foo => foo.Factor);

                IAdapterFactory <Foo, IFooView> systemUnderTest = AdapterFactoryGenerator.Instance.Generate <Foo, IFooView>(configuration.Mappings);

                // Delay to allow CPU and I/O to drop
                Thread.Sleep(TimeSpan.FromSeconds(2));

                var       foo1 = new Foo("test foo", Guid.NewGuid(), 1);
                const int numberOfInstances = 2000000;
                var       mappingServiceMs  = (long)StopwatchContext.Timed(
                    () =>
                {
                    for (int i = 0; i < numberOfInstances; i++)
                    {
                        systemUnderTest.Create(foo1);
                    }
                }).TotalMilliseconds;
                // ReSharper disable ImplicitlyCapturedClosure
                var hardCodedMs = (long)StopwatchContext.Timed(
                    () =>
                    // ReSharper restore ImplicitlyCapturedClosure
                {
                    for (int i = 0; i < numberOfInstances; i++)
                    {
                        // ReSharper disable ObjectCreationAsStatement
                        new HardCodedFooAdapter(foo1);
                        // ReSharper restore ObjectCreationAsStatement
                    }
                }).TotalMilliseconds;
                double mappingServicePerInstanceSeconds = (mappingServiceMs / 1000.0) / numberOfInstances;
                double hardCodedPerInstanceSeconds      = (hardCodedMs / 1000.0) / numberOfInstances;
                double performanceDifference            = mappingServiceMs / (double)hardCodedMs;

                Console.WriteLine("Generated Adapter:  {0:0.0000000000000}s per instance, {1:0.000}s total, {2} instances.", mappingServicePerInstanceSeconds, mappingServiceMs / 1000.0, numberOfInstances);
                Console.WriteLine("Hard-coded Adapter: {0:0.0000000000000}s per instance, {1:0.000}s total, {2} instances.", hardCodedPerInstanceSeconds, hardCodedMs / 1000.0, numberOfInstances);
                Console.WriteLine();
                Console.WriteLine("Relative time for generated version: {0:00.00}x slower", performanceDifference);
                Console.WriteLine("Cost per 100 instances as percentage of 50ms page load: {0:000.000000}%", ((mappingServicePerInstanceSeconds * 100) / 0.050) * 100.0);

                Assert.That(performanceDifference, Is.LessThan(30.0));
            }