Beispiel #1
0
        // ~ Methods

///
///	 <summary> * Tests the class PrintfFormat. If everything is OK, the string "Passed" is
///	 * printed, and the program exits with status 0. Otherwise, diagnostics and
///	 * a stack trace are printed, and the program exits with status 1.
///	 *  </summary>
///	 * <param name="args">
///	 *            Program arguments.<br>
///	 *            "-help" prints a usage message.<br>
///	 *            "-timing" compares how long it takes to output a double
///	 *            compared to the regular Java string conversion. </param>
///
        static void Main(string[] args)
        {
            bool testTiming = false;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("-timing"))
                {
                    testTiming = true;
                }
                else if (args[i].Equals("-help"))
                {
                    printUsage();
                    Environment.Exit(0);
                }
                else
                {
                    printUsage();
                    Environment.Exit(1);
                }
            }

            if (testTiming)
            {
                try
                {
                    int    i;
                    int    k;
                    int    nsamp = 10;
                    int    niter = 1000;
                    long   t0;
                    long   t1;
                    double texec;

                    // call once to init
                    t0 = System.DateTime.Now.Ticks;

                    for (i = 0; i < niter; i++)
                    {
                        for (k = 0; k < nsamp; k++)
                        {
                            Convert.ToString(k * 1.111111 * Math.Pow(10, k));
                        }
                    }

                    t1    = System.DateTime.Now.Ticks;
                    texec = (1000 * (t1 - t0)) / (double)(niter * nsamp);
                    Console.WriteLine("Typical time for Double.toString(): " + texec + " usec");

                    PrintfFormat fmt = new PrintfFormat("%g");
                    t0 = System.DateTime.Now.Ticks;

                    for (i = 0; i < niter; i++)
                    {
                        for (k = 0; k < nsamp; k++)
                        {
                            fmt.tostr(k * 1.111111 * Math.Pow(10, k));
                        }
                    }

                    t1    = System.DateTime.Now.Ticks;
                    texec = (1000 * (t1 - t0)) / (double)(niter * nsamp);
                    Console.WriteLine("Typical time for PrintfFormat.tostr(double): " + texec + " usec");
                }
                catch (Exception e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                    Environment.Exit(1);
                }
            }
            else
            {
                try
                {
                    testLots();
                }
                catch (Exception e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                    Environment.Exit(1);
                }

                Console.WriteLine("\nPassed\n");
                Environment.Exit(0);
            }
        }
Beispiel #2
0
 ///
 ///      <summary> * Prints a char in accordance with the supplied
 ///      * PrintfFormat object.
 ///      * </summary>
 ///      * <param name="fmt"> Formatting object </param>
 ///      * <param name="x"> Char to output </param>
 ///      * <seealso cref= PrintfFormat </seealso>
 ///
 public virtual void printf(PrintfFormat fmt, char x)
 {
     Write(fmt.tostr(x));
 }