Esempio n. 1
0
 /// <summary>
 /// Object to data transfer object
 /// </summary>
 /// <param name="authentication"></param>
 /// <returns></returns>
 public static TimeRegDTO ObjectToDTO(TimeReg obj)
 {
     return(new TimeRegDTO {
         timestamp = DataConvert.DateTimeToJsonString(obj.timestamp),
         updated = DataConvert.DateTimeToJsonString(obj.updated)
     });
 }// End of ObjectToDTO function
Esempio n. 2
0
    private static long OutterBenchmark(BenchmarkMethod method, long time, long warmups, long iters)
    {
        TimeReg timeReg = new TimeReg();

        Round(method, time, warmups, timeReg, "# Warmup ");
        return(Round(method, time, iters, timeReg, ""));
    }
Esempio n. 3
0
        private static long Round(BenchmarkMethod method, long time, long iters, TimeReg timeReg, string msg)
        {
            long bestNumOps = 0;
            long numOps;

            for (long i = 1; i <= iters; ++i)
            {
                Console.Write("{0}Iteration {1,2}: ", msg, i);
                InnerBenchmark(method, time, timeReg);
                numOps = (long)((double)timeReg.ops / timeReg.time * 1000);   // numOps = n. operacoes /s = frequencia

                if (numOps > bestNumOps)
                {
                    bestNumOps = numOps;
                }
                // periodo = 1 / frequencia
                // periodo (nanosegundos) = (1 / frequencia) * 10^9
                Console.WriteLine("{0} ops/s\t{1,8:0.00} ns", numOps, 1.0 / numOps * 1.0e9);
                Collect();
                // No final de cada iteracao existe um GC.Collect() para limpar objetos temporarios
                // que foram criados durante a iteracao.
                // Usado para evitar que ocorra um GC.Collect() a meio das proximas
                // iteracoes, o que poderia influenciar o tempo do teste de desempenho
            }

            return(bestNumOps);
        }
Esempio n. 4
0
        }// End of Constructor function

        /// <summary>
        /// Add time register
        /// </summary>
        /// <param name="time_reg"></param>
        /// <param name="user_log"></param>
        /// <returns></returns>
        public TimeReg addTimeReg(TimeReg time_reg, UserSystem user_log)
        {
            return(http_service.JSONHttpPettitionObject <TimeReg>(
                       HttpMethod.POST,
                       GetType().Name.ToLower().Replace(
                           TWords.SERVICE,
                           TWords.SLASH),
                       JsonConvert.SerializeObject(
                           TimeRegAdapter.ObjectToDTO(
                               time_reg))));
        }// End of addTimeReg function
Esempio n. 5
0
        public static IList <TimeReg> DTOsToObjects(IList <TimeRegDTO> dtos)
        {
            IList <TimeReg> list = new List <TimeReg>();

            foreach (TimeRegDTO dto in dtos)
            {
                TimeReg obj = DTOToObject(dto);
                list.Add(obj);
            }

            return(list);
        }
Esempio n. 6
0
        private static void InnerBenchmark(BenchmarkMethod method, long time, TimeReg timeReg)
        {
            long ops = 0;
            long begTime = Environment.TickCount, curTime, endTime = begTime + time;

            do
            {
                method.Invoke();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                method();
                ops += 32; // Usado para diminuir a frequencia com que Environment.TickCount e' chamado

                /*
                 * method();
                 * ops++;
                 */

                curTime = Environment.TickCount; // Environment.TickCount devolve tempo decorrido em milisegundos
            } while (curTime < endTime);

            timeReg.ops  = ops;
            timeReg.time = curTime - begTime;
        }
Esempio n. 7
0
    private static void InnerBenchmark(Func <object> func, int time, TimeReg timeReg)
    {
        int ops = 0;
        int begTime = Environment.TickCount, curTime, endTime = begTime + time;

        do
        {
            func(); func(); func(); func(); func(); func(); func(); func();
            func(); func(); func(); func(); func(); func(); func(); func();
            func(); func(); func(); func(); func(); func(); func(); func();
            func(); func(); func(); func(); func(); func(); func(); func();
            curTime = Environment.TickCount;
            ops    += 32;
        } while (curTime < endTime);
        timeReg.ops  = ops;
        timeReg.time = curTime - begTime;
    }
Esempio n. 8
0
    private static void InnerBenchmark(BenchmarkMethod method, long time, TimeReg timeReg)
    {
        long ops = 0;
        long begTime = Environment.TickCount, curTime, endTime = begTime + time;

        do
        {
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            method(); method(); method(); method(); method(); method(); method(); method();
            ops    += 32;
            curTime = Environment.TickCount;
        } while (curTime < endTime);
        timeReg.ops  = ops;
        timeReg.time = curTime - begTime;
    }
Esempio n. 9
0
    private static void OutterBenchmark(Func <object> func, int time, int iters, int warmups)
    {
        TimeReg timeReg = new TimeReg();

        for (int w = 1; w <= warmups; ++w)
        {
            Console.Write("# Warmup Iteration {0,2}: ", w);
            InnerBenchmark(func, time, timeReg);
            Console.WriteLine("{0} ops/s", (((double)timeReg.ops) / timeReg.time) * 1000);
            Collect();
        }
        for (int i = 1; i <= iters; ++i)
        {
            Console.Write("Iteration {0,2}: ", i);
            InnerBenchmark(func, time, timeReg);
            Console.WriteLine("{0} ops/s", (((double)timeReg.ops) / timeReg.time) * 1000);
            Collect();
        }
    }
Esempio n. 10
0
    private static long Round(BenchmarkMethod method, long time, long iters, TimeReg timeReg, string msg)
    {
        long bestNumOps = 0;
        long numOps;

        for (long i = 1; i <= iters; ++i)
        {
            Console.Write("{0}Iteration {1,2}: ", msg, i);
            InnerBenchmark(method, time, timeReg);
            numOps = (long)((((double)timeReg.ops) / timeReg.time) * 1000);
            if (numOps > bestNumOps)
            {
                bestNumOps = numOps;
            }
            Console.WriteLine("{0} ops/s\t{1,8:0.00} ns", numOps, (1.0 / numOps) * 1.0e9);
            Collect();
        }
        return(bestNumOps);
    }
Esempio n. 11
0
        }// End of addTimeReg function

        /// <summary>
        /// Delete time register
        /// </summary>
        /// <param name="time_reg"></param>
        /// <param name="user_log"></param>
        /// <returns></returns>
        public bool deleteTimeReg(TimeReg time_reg, UserSystem user_log)
        {
            throw new NotImplementedException();
        }// End of deleteTimeReg function
Esempio n. 12
0
        }// End of Report Control constructor

        public IList <ReportVO> createReportsCategories(Competition competition, Category cat)
        {
            // init the reports array
            IList <ReportVO> reports = new List <ReportVO>();

            // 5.- get the time registers for the respective register
            // Get the competitors
            pbDataProgress.Value = 0;
            IList <Competitor> competitors = event_control.competitor_service.getAll(null);

            pbDataProgress.Value = 33;
            IList <Category> categories = event_control.category_service.getAll(null);

            pbDataProgress.Value = 66;
            // Init temporal shit
            IList <Register> registers = getRegisters(competition);

            pbDataProgress.Value = 100;
            IList <TimeReg> time_regs = new List <TimeReg>();

            // 4.- get the registes for the repective comeptition
            foreach (Register r in registers)
            {
                ReportVO report = new ReportVO();
                // 6.- get the competitor for the respective regiser
                Competitor comp = competitors.Where(competitor => competitor.id == r.competitor).ToList().First();
                // 7.- create the report object with all the data you have-
                // the competition, register, competitor, time registers
                time_regs = event_control.time_reg_service.getByRegister(r, null);

                TimeReg time_reg_temp = new TimeReg();
                time_reg_temp.register = r.id;
                time_reg_temp.time     = txtStartTime.Text;
                time_regs.Insert(0, time_reg_temp);

                // 8.- fill the list of times on the report with the time registers
                report.competitors_name = string.Format("{0} {1}", comp.name, comp.second_name);
                report.competitor_num   = r.competitor_num;
                report.category         = categories.Where(category => category.id == r.category).ToList().First().name;
                // loop time registers
                foreach (TimeReg tr in time_regs)
                {
                    if (tr != time_regs.First())
                    {
                        TimeSpan dif = DateTime.Parse(tr.time).Subtract(DateTime.Parse(time_regs.First().time));
                        report.times.Add(dif.ToString());
                    }
                }
                // Validate it the time_registers has none, it means something went wrong with the competitor
                if (time_regs.Count > 0)
                {
                    report.disqualified = false;
                    report.total_time   = DateTime.Parse(time_regs.Last().time).Subtract(DateTime.Parse(time_regs.First().time)).ToString();
                }
                // Else just put a 0; us tin case
                else
                {
                    report.disqualified = true;
                    report.total_time   = "00:00:00";
                }
                // Add the report to the reports array
                reports.Add(report);
            }
            // Fill the array that will contain the number
            fill_array(reports);
            // order the reports  globally
            order_global_reports_by_category(reports, categories, cat);
            // Return the reports just in case duh!
            return(reports);
        }// End of createReportsCategories function