File:Array List LinkedList Queue (C sharp).svg

Original file(SVG file, nominally 1,000 × 698 pixels, file size: 514 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary edit

Description
English: Processing time of double[](System.Array), System.Collections.Generic.List<double>, System.Collections.Generic.LinkedList<double>, System.Collections.Generic.Queue<double> on .NET Framework 4.0 with C#. See also #code.
日本語: .NET Framework 4.0のC#での、double[](System.Array), System.Collections.Generic.List<double>, System.Collections.Generic.LinkedList<double>, System.Collections.Generic.Queue<double>の処理時間の比較。コードも参照。
Date
Source Own work
Author aokomoriuta(青子守歌)

Licensing edit

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Creative Commons license
Creative Commons Attribution iconCreative Commons Noncommercial icon
This file is licensed under the Creative Commons Attribution-Noncommercial 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must attribute the work in the manner specified by the author or :licensor (but not in any way that suggests that they endorse you or your use of the work).
  • noncommercial – You may not use this work for commercial purposes.
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
You may select the license of your choice.

code edit

using System;
using System.Collections.Generic;

namespace LWisteria.List
{
	/// <summary>
	/// Listの比較をするメインクラス
	/// </summary>
	static class ListMain
	{
		/// <summary>
		/// エントリーポイント
		/// </summary>
		/// <returns></returns>
		static int Main()
		{
			// ストップウォッチを生成
			System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

			// 最大要素数
			int maxN = 1000000;

			Console.WriteLine("#,Array,List,LinkedList,Queue");

			
			// 要素数を2倍ずつに増やしていく
			for(double m = 10; m < maxN; m *= new System.Random().NextDouble()/2 + 1)
			{
				// intにキャスト
				int n = (int)m;

				Console.Write("{0},", n);

				// ストップウォッチ開始
				stopwatch.Start();

				// Listを生成
				double[] array = new double[n];

				// nまで
				for(int i = 0; i < n; i++)
				{
					// √を計算して追加
					array[i] = System.Math.Sqrt(i);
				}

				// 合計値を初期化して、全要素について
				double sumArray = 0;
				foreach(double value in array)
				{
					// 合計する
					sumArray += value;
				}
				// ストップウォッチ停止
				stopwatch.Stop();

				// 結果出力
				Console.Write("{0},", stopwatch.ElapsedTicks);
				stopwatch.Reset();

				/*****************************************************/

				// ストップウォッチ開始
				stopwatch.Start();

				// Listを生成
				List<double> list = new List<double>();

				// nまで
				for(int i = 0; i < n; i++)
				{
					// √を計算して追加
					list.Add(System.Math.Sqrt(i));
				}

				// 合計値を初期化して、全要素について
				double sumList = 0;
				foreach(double value in list)
				{
					// 合計する
					sumList += value;
				}
				// ストップウォッチ停止
				stopwatch.Stop();

				// 結果出力
				Console.Write("{0},", stopwatch.ElapsedTicks);
				stopwatch.Reset();

				/*****************************************************/

				// ストップウォッチ開始
				stopwatch.Start();

				// LinkedListを生成
				LinkedList<double> linkedList = new LinkedList<double>();

				// nまで
				for(int i = 0; i < n; i++)
				{
					// √を計算して追加
					linkedList.AddLast(System.Math.Sqrt(i));
				}

				// 合計値を初期化して、全要素について
				double sumLinkedList = 0;
				foreach(double value in linkedList)
				{
					// 合計する
					sumLinkedList += value;
				}
				// ストップウォッチ停止
				stopwatch.Stop();

				// 結果出力
				Console.Write("{0},", stopwatch.ElapsedTicks);
				stopwatch.Reset();

				/*****************************************************/

				// ストップウォッチ開始
				stopwatch.Start();

				// Queueを生成
				Queue<double> queue = new Queue<double>();

				// nまで
				for(int i = 0; i < n; i++)
				{
					// √を計算して追加
					queue.Enqueue(System.Math.Sqrt(i));
				}

				// 合計値を初期化して、全要素について
				double sumQueue = 0;
				foreach(double value in queue)
				{
					// 合計する
					sumQueue += value;
				}
				// ストップウォッチ停止
				stopwatch.Stop();

				// 結果出力
				Console.Write("{0},", stopwatch.ElapsedTicks);
				stopwatch.Reset();

				/*****************************************************/

				Console.WriteLine("{0}", sumArray == sumList && sumList == sumLinkedList && sumLinkedList == sumQueue);
			}

			// 終了コードを返す
			return System.Environment.ExitCode;
		}
	}
}

[Hide]

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current05:28, 24 February 2011Thumbnail for version as of 05:28, 24 February 20111,000 × 698 (514 KB)青子守歌 (talk | contribs)bug fix
15:10, 23 February 2011Thumbnail for version as of 15:10, 23 February 2011442 × 306 (121 KB)青子守歌 (talk | contribs)== {{int:filedesc}} == {{subst:User:青子守歌/own work|Figures| |en = Processing time of double[](System.Array), System.Collections.Generic.List<double>, System.Collections.Generic.LinkedList<double>, System.Collections.Generic.Queue<double>

There are no pages that use this file.