-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (66 loc) · 2.07 KB
/
Program.cs
File metadata and controls
86 lines (66 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections.Generic;
using System.Diagnostics;
public static class Program {
public static void Main() {
ListTest();
DictionaryTest();
// GenericMethod.Entry();
// GenericClass.Entry();
// DelegateTutorial.Entry();
// Sample.Entry();
// Architecture.Entry();
// Collection_List_App.Entry();
// Collection_Dictionary_App.Entry();
// ReflectionSample.Reflection_Tutorial.Entry();
}
static void ListTest() {
// 空间
int[] array = new int[1000000];
List<int> list = new List<int>(1000000); // 4 和 1000000 有区别
Stopwatch sw = new Stopwatch();
// 开方
double value = 2;
double min = 0;
double max = 2;
double current = 0;
int count = 0;
while (count < 1000000) {
current = (min + max) / 2f;
if (current * current == value) {
break;
} else if (current * current > value) {
max = current;
} else {
min = current;
}
count++;
}
System.Console.WriteLine("current: " + current);
// 时间
for (int i = 0; i < 100_0000; i++) {
list.Add(i);
}
int index = list.FindIndex(value => value == 1000_0000);
sw.Start();
list.BinarySearch(810000);
sw.Stop();
double ms = sw.Elapsed.TotalMicroseconds;
System.Console.WriteLine("List: " + ms);
// List Find: 1800
// malloc(sizeof(int) * 1000000);
}
static void DictionaryTest() {
Dictionary<int, int> dict = new Dictionary<int, int>(4);
for (int i = 0; i < 100_0000; i++) {
dict.Add(i, i);
}
bool has = dict.TryGetValue(100_0000, out int value);
Stopwatch sw = new Stopwatch();
sw.Start();
foreach (var item in dict) {
}
sw.Stop();
double ms = sw.Elapsed.TotalMicroseconds;
System.Console.WriteLine("Dictionary: " + ms);
}
}