⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.cs

📁 遍里数据库集合里的数据
💻 CS
字号:
using System;
using System.Collections;

using Iterations;

namespace Test
{
  class Test
  {
    private double d;
    private int reps;
    private int size;
    private double seconds;
    private Data data = null;
    private DateTime before;
    private TimeSpan total;

    [STAThread]
    static void Main(string[] args)
    {
      Test test;
      if ( args.Length > 1 ) 
      {
        test = new Test( int.Parse( args[0] ), int.Parse( args[1] ));
      } 
      else 
      {
        test = new Test();
      }
      test.TestAll();
    }

    public Test() : this( 1000, 1000000 )
    {
    }

    public Test( int reps, int size )
    {
      this.reps = reps;
      this.size = size;
      data = new Data( size );
    }

    private void TestAll()
    {
      System.Console.WriteLine();
      System.Console.WriteLine( "repetitions: " + reps );
      System.Console.WriteLine( "iterations: " + size.ToString( "e" ));
      System.Console.WriteLine();
      TestEnumeration();
      TestIndexing();
      TestIndirectArrays();
      TestDirectArrays();
      TestPointerMath();
      System.Console.WriteLine();
    }

    private void TestEnumeration() 
    {
      total = new TimeSpan( 0 );
      for ( int i = 0; i < reps; i++ ) 
      {
        before = DateTime.Now;
        IEnumerator enumerator = data.GetEnumerator();
        while ( enumerator.MoveNext() ) 
        {
          d = (double) enumerator.Current;
        }
        total += DateTime.Now - before;
      }
      seconds = total.Seconds + ( total.Milliseconds / 1000.0 );
      System.Console.WriteLine( "Enumeration: \t\t" + seconds + " seconds" );
    }

    private void TestIndexing()
    {
      total = new TimeSpan( 0 );
      for ( int i = 0; i < reps; i++ ) 
      {
        before = DateTime.Now;
        for ( int j = 0; j < size; j++ )
        {
          d = data[j];
        }
        total += DateTime.Now - before;
      }
      seconds = total.Seconds + ( total.Milliseconds / 1000.0 );
      System.Console.WriteLine( "Indexing: \t\t" + seconds + " seconds" );      
    }

    private void TestIndirectArrays()
    {
      total = new TimeSpan( 0 );
      for ( int i = 0; i < reps; i++ ) 
      {
        before = DateTime.Now;
        for ( int j = 0; j < size; j++ )
        {
          d = data.Array[j];
        }
        total += DateTime.Now - before;
      }
      seconds = total.Seconds + ( total.Milliseconds / 1000.0 );
      System.Console.WriteLine( "Indirect Arrays: \t" + seconds + " seconds" ); 
    }

    private void TestDirectArrays()
    {
      total = new TimeSpan( 0 );
      for ( int i = 0; i < reps; i++ ) 
      {
        before = DateTime.Now;
        double[] array = data.Array;
        for ( int j = 0; j < size; j++ )
        {
          d = array[j];
        }
        total += DateTime.Now - before;
      }
      seconds = total.Seconds + ( total.Milliseconds / 1000.0 );
      System.Console.WriteLine( "Direct Arrays: \t\t" + seconds + " seconds" );
    }

    private void TestPointerMath()
    {
      total = new TimeSpan( 0 );
      for ( int i = 0; i < reps; i++ ) 
      {
        before = DateTime.Now;
        Pointer.iterate( data );
        total += DateTime.Now - before;
      }
      seconds = total.Seconds + ( total.Milliseconds / 1000.0 );
      System.Console.WriteLine( "Pointer Math: \t\t" + seconds + " seconds" );
    }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -