コード例 #1
0
        /// <summary>
        /// Starts a new performance consumer and returns the instance that just started.
        /// </summary>
        /// <returns></returns>
        public static PerformanceInfoConsumer StartNew(string name)
        {
            var performance = new PerformanceInfoConsumer(name);

            performance.Start();
            return(performance);
        }
コード例 #2
0
        /// <summary>
        /// Tests performance for the given action.
        /// </summary>
        public static void TestPerf(this Action action, string name)
        {
            var info = new PerformanceInfoConsumer(name);

            info.Start();
            action();
            info.Stop();
        }
コード例 #3
0
        /// <summary>
        /// Tests performance for the given function.
        /// </summary>
        public static TResult TestPerf <T, TResult>(this Func <T, TResult> func, string name, T a)
        {
            var info = new PerformanceInfoConsumer(name);

            info.Start();
            var res = func(a);

            info.Stop();
            return(res);
        }
コード例 #4
0
        /// <summary>
        /// Tests performance for the given function.
        /// </summary>
        public static T TestPerf <T>(this Func <T> func, string name)
        {
            var info = new PerformanceInfoConsumer(name);

            info.Start();
            var res = func();

            info.Stop();
            return(res);
        }
コード例 #5
0
        /// <summary>
        /// Executes the given test on the given router.
        /// </summary>
        public static Route Test(MultimodalRouter router, FeatureCollection test)
        {
            var source = test.Features.FirstOrException(x =>
                                                        x.Attributes.Contains("type", "source"), "Invalid test data: no source found.");
            var target = test.Features.FirstOrException(x =>
                                                        x.Attributes.Contains("type", "target"), "Invalid test data: no target found");

            var sourceLocation = (source.Geometry as Point).Coordinate;
            var targetLocation = (target.Geometry as Point).Coordinate;

            var sourceProfile = Itinero.Profiles.Profile.GetRegistered(source.Attributes.FirstOrException(x => x == "profile",
                                                                                                          "Invalid test data: no vehicle profile found on source.").ToInvariantString());
            var targetProfile = Itinero.Profiles.Profile.GetRegistered(target.Attributes.FirstOrException(x => x == "profile",
                                                                                                          "Invalid test data: no vehicle profile found on target.").ToInvariantString());

            var resolvedSource = router.Router.Resolve(sourceProfile, sourceLocation);
            var resolvedTarget = router.Router.Resolve(targetProfile, targetLocation);

            var result = test.Features.First(x => x.Attributes.Contains("type", "result"));
            var name   = result.Attributes.FirstOrException(x => x == "name", "Name of test case not found, expected on result geometry.").ToInvariantString();

            Contract.Requires(name != null, "Name of test case not set.");

            var performanceInfoConsumer = new PerformanceInfoConsumer(name, 5000);

            var time = DateTime.Now;

            if (result.Attributes.GetNames().Contains("departuretime") &&
                DateTime.TryParseExact(result.Attributes.FirstOrException(x => x == "departuretime", string.Empty).ToInvariantString(),
                                       "yyyyMMddHHmm", System.Globalization.CultureInfo.InvariantCulture,
                                       DateTimeStyles.None, out time))
            {
                performanceInfoConsumer.Start();
                var route = router.TryEarliestArrival(time, resolvedSource, sourceProfile, resolvedTarget, targetProfile, EarliestArrivalSettings.Default);

                Assert.IsFalse(route.IsError, "Route was not found.");

                //object value;
                //if (result.Attributes.TryGetValue("time", out value))
                //{
                //    var timeResult = (long)value;
                //    Assert.AreEqual(timeResult, route.Value.TotalTime, Settings.MinimumTotalTimeDifference);
                //}
                //performanceInfoConsumer.Stop();
                //File.WriteAllText("temp.geojson", route.Value.ToGeoJson());

                return(route.Value);
            }
            else
            {
                throw new Exception("Invalid test data: no departure time set.");
            }
        }
コード例 #6
0
        /// <summary>
        /// Tests performance for the given action.
        /// </summary>
        public static void TestPerf(this Action action, string name, int count)
        {
            var info = new PerformanceInfoConsumer(name + " x " + count.ToInvariantString(), 10000);

            info.Start();
            while (count > 0)
            {
                action();
                count--;
            }
            info.Stop();
        }
コード例 #7
0
        /// <summary>
        /// Tests performance for the given function.
        /// </summary>
        public static T TestPerf <T>(this Func <T> func, string name, int count)
        {
            var res  = default(T);
            var info = new PerformanceInfoConsumer(name + " x " + count.ToInvariantString(), 10000);

            info.Start();
            while (count > 0)
            {
                res = func();
                count--;
            }
            info.Stop();
            return(res);
        }