示例#1
0
文件: Gradient.cs 项目: omidm/naiad
    static void Main(string[] args)
    {
        if (args.Length != 3)
        {
            PrintHelp();
            return;
        }
        else if (args.Length == 1)
        {
            if (args[0] == "--help" || args[0] == "-h")
            {
                PrintHelp();
                return;
            }
        }

        Int32  dimension     = Int32.Parse(args[0]);
        Int32  iteration_num = Int32.Parse(args[1]);
        double sample_num_m  = Convert.ToDouble(args[2]);

        Console.Out.WriteLine("dimension: " + dimension);
        Console.Out.WriteLine("iteration_num: " + iteration_num);
        Console.Out.WriteLine("sample_num in million: " + sample_num_m);
        Console.Out.Flush();


        Gradient g =
            new Gradient(dimension,
                         iteration_num,
                         sample_num_m);

        long   stamp   = 0;
        double elapsed = 0;

        stamp = Stopwatch.GetTimestamp();
        g.GenerateSamples();
        elapsed = (double)(Stopwatch.GetTimestamp() - stamp) / (double)(Stopwatch.Frequency);
        Console.Out.WriteLine("Generating samples(ms): {0:F2} ", 1000 * elapsed);


        List <double> elapsed_list = new List <double>();

        for (int i = 0; i < g.iteration_num_; ++i)
        {
            stamp = Stopwatch.GetTimestamp();
            g.Advance();
            elapsed = (double)(Stopwatch.GetTimestamp() - stamp) / (double)(Stopwatch.Frequency);
            Console.Out.WriteLine("Iteration {0:D2} elapsed(ms): {1:F2} ", i, 1000 * elapsed);
            elapsed_list.Add(1000 * elapsed);
        }
        Console.Out.WriteLine("Average gradient computation for {0:D2} iterations(ms): {1:F2} ",
                              g.iteration_num_, elapsed_list.Average(x => x));
    }