Advertisement
Guest User

Untitled

a guest
Sep 27th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6.  
  7. namespace bench1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] d = new double[1000000];
  14.             double i;
  15.             int j;
  16.             for (i = 0, j = 0; j < d.Length; i += 0.00351, j++)
  17.                 d[j] = i;
  18.  
  19.             Stopwatch t = new Stopwatch();
  20.  
  21.             //--------------------------------------------------------------------
  22.             Console.Write("test 1 - fft: ");
  23.             t.Start();
  24.             test1(false, false, true, d);
  25.             t.Stop();
  26.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  27.  
  28.             Console.Write("test 2 - fft: ");
  29.             t.Reset();
  30.             t.Start();
  31.             test2(false, false, true, d);
  32.             t.Stop();
  33.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  34.             //--------------------------------------------------------------------
  35.             Console.Write("test 1 - tft: ");
  36.             t.Reset();
  37.             t.Start();
  38.             test2(true, false, true, d);
  39.             t.Stop();
  40.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  41.  
  42.             Console.Write("test 2 - tft: ");
  43.             t.Reset();
  44.             t.Start();
  45.             test2(true, false, true, d);
  46.             t.Stop();
  47.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  48.             //--------------------------------------------------------------------
  49.             Console.Write("test 1 - ttt: ");
  50.             t.Reset();
  51.             t.Start();
  52.             test2(true, true, true, d);
  53.             t.Stop();
  54.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  55.  
  56.             Console.Write("test 2 - ttt: ");
  57.             t.Reset();
  58.             t.Start();
  59.             test2(true, true, true, d);
  60.             t.Stop();
  61.             Console.Write(t.ElapsedMilliseconds.ToString() + " ms\n");
  62.  
  63.             Console.ReadKey(true);
  64.         }
  65.  
  66.         static void test1(bool c1, bool c2, bool c3, double[] dati)
  67.         {
  68.             for (int i = 0; i < dati.Length; i++) {
  69.                 if (c1) testFun1(dati[i]);
  70.                 if (c2) testFun2(dati[i]);
  71.                 if (c3) testFun3(dati[i]);
  72.             }
  73.         }
  74.  
  75.         static void test2(bool c1, bool c2, bool c3, double[] dati)
  76.         {
  77.             if (c1) for (int i = 0; i < dati.Length; i++) testFun1(dati[i]);
  78.             if (c2) for (int i = 0; i < dati.Length; i++) testFun2(dati[i]);
  79.             if (c3) for (int i = 0; i < dati.Length; i++) testFun3(dati[i]);
  80.         }
  81.  
  82.         static void testFun1(double d)
  83.         {
  84.             Random r = new Random(TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Today).Second);
  85.             int[] a = new int[20];
  86.  
  87.             for (int i = 0; i < a.Length; i++)
  88.                 a[i] = r.Next() + Convert.ToInt32(d);
  89.  
  90.             double a1, a2, b1, b2;
  91.  
  92.             a1 = Convert.ToDouble(a[r.Next(a.Length)]);
  93.             a2 = Convert.ToDouble(a[r.Next(a.Length)]);
  94.  
  95.             if (a1 > 15 && a1 < 1800 || a2 - a1 > 0 && a2 != 18)
  96.                 b1 = b2 = Convert.ToDouble(a[0].ToString());
  97.             else
  98.                 b1 = b2 = 0;
  99.  
  100.             double x = a1 * (a2 - a1) * Math.Cos(Math.Sin(b1 * 5)) / Math.Tanh(Math.Cos(a2) + Math.Sin(a1));
  101.             x *= 2.0142145 / Math.Exp(d);
  102.         }
  103.  
  104.         static void testFun2(double d)
  105.         {
  106.             Random r = new Random(TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Today).Second);
  107.             int[] a = new int[20];
  108.  
  109.             for (int i = 0; i < a.Length; i++)
  110.                 a[i] = r.Next() + Convert.ToInt32(d);
  111.  
  112.             double a1, a2, b1, b2;
  113.  
  114.             a1 = Convert.ToDouble(a[r.Next(a.Length)]);
  115.             a2 = Convert.ToDouble(a[r.Next(a.Length)]);
  116.  
  117.             if (a1 > 15 && a1 < 1800 || a2 - a1 > 0 && a2 != 18)
  118.                 b1 = b2 = Convert.ToDouble(a[0].ToString());
  119.             else
  120.                 b1 = b2 = 0;
  121.  
  122.             double x = a1 * (a2 - a1) * Math.Cos(Math.Sin(b1 * 5)) / Math.Tanh(Math.Cos(a2) + Math.Sin(a1));
  123.             x *= 2.0142145 / Math.Exp(d);
  124.         }
  125.  
  126.         static void testFun3(double d)
  127.         {
  128.             Random r = new Random(TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Today).Second);
  129.             int[] a = new int[20];
  130.  
  131.             for (int i = 0; i < a.Length; i++)
  132.                 a[i] = r.Next() + Convert.ToInt32(d);
  133.  
  134.             double a1, a2, b1, b2;
  135.  
  136.             a1 = Convert.ToDouble(a[r.Next(a.Length)]);
  137.             a2 = Convert.ToDouble(a[r.Next(a.Length)]);
  138.  
  139.             if (a1 > 15 && a1 < 1800 || a2 - a1 > 0 && a2 != 18)
  140.                 b1 = b2 = Convert.ToDouble(a[0].ToString());
  141.             else
  142.                 b1 = b2 = 0;
  143.  
  144.             double x = a1 * (a2 - a1) * Math.Cos(Math.Sin(b1 * 5)) / Math.Tanh(Math.Cos(a2) + Math.Sin(a1));
  145.             x *= 2.0142145 / Math.Exp(d);
  146.         }
  147.     }
  148. }
  149.  
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement