using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PerformanceTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string[] keys;
public object[] values;
private void btnCreateArray_Click(object sender, EventArgs e)
{
int arraySize = int.Parse(txtArraySize.Text);
keys = new string[arraySize];
values = new object[arraySize];
int numberOfInteger = arraySize / 3;
int numberOfDouble = arraySize / 3;
int numberOfString = arraySize - (numberOfDouble + numberOfInteger);
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
keys[i] = GetRandomString();
}
for (int i = 0; i < numberOfInteger; i++)
{
int randomvalue;
using (RNGCryptoServiceProvider rg = new RNGCryptoServiceProvider())
{
byte[] rno = new byte[4];
rg.GetBytes(rno);
randomvalue = BitConverter.ToInt32(rno, 0);
}
values[i] = randomvalue;
}
for (int i = numberOfInteger; i < (numberOfDouble + numberOfInteger); i++)
{
values[i] = new Random().NextDouble() + i;
}
for (int i = (numberOfDouble + numberOfInteger); i < arraySize; i++)
{
values[i] = GetRandomString();
}
MessageBox.Show("Diziler Oluşturuldu");
}
public static string GetRandomString()
{
string path = Path.GetRandomFileName();
path = path.Replace(".", "");
return path;
}
private void btnCreateDictionary_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
Dictionary<string, object> dictionary = new Dictionary<string, object>();
Hashtable hashtable = new Hashtable();
ConcurrentDictionary<string, object> concurrentDictionary = new ConcurrentDictionary<string, object>();
SortedList<string, object> sortedList = new SortedList<string, object>();
SortedDictionary<string, object> sortedDictionary = new SortedDictionary<string, object>();
StringDictionary stringDictionary = new StringDictionary();
stopwatch.Start();
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
dictionary.Add(keys[i], values[i]);
}
stopwatch.Stop();
lblDictionary.Text = stopwatch.Elapsed.ToString();
stopwatch.Reset();
stopwatch.Start();
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
hashtable.Add(keys[i], values[i]);
}
stopwatch.Stop();
lblHashtable.Text = stopwatch.Elapsed.ToString();
stopwatch.Reset();
stopwatch.Start();
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
concurrentDictionary.TryAdd(keys[i], values[i]);
}
stopwatch.Stop();
lblConcurrentDictionary.Text = stopwatch.Elapsed.ToString();
stopwatch.Reset();
//stopwatch.Start();
//for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
//{
// sortedList.Add(keys[i], values[i]);
//}
//stopwatch.Stop();
//lblSortedList.Text = stopwatch.Elapsed.ToString();
//stopwatch.Reset();
stopwatch.Start();
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
sortedDictionary.Add(keys[i], values[i]);
}
stopwatch.Stop();
lblSortedDictionary.Text = stopwatch.Elapsed.ToString();
stopwatch.Reset();
stopwatch.Start();
for (int i = 0; i < int.Parse(txtArraySize.Text); i++)
{
stringDictionary.Add(keys[i], keys[i]);
}
stopwatch.Stop();
lblStringDictionary.Text = stopwatch.Elapsed.ToString();
stopwatch.Reset();
}
}
}
