-
-
Notifications
You must be signed in to change notification settings - Fork 560
/
DictionaryBenchmark.cs
72 lines (63 loc) · 1.46 KB
/
DictionaryBenchmark.cs
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
using Jint.Collections;
using BenchmarkDotNet.Attributes;
namespace Jint.Benchmark;
[MemoryDiagnoser]
public class DictionaryBenchmark
{
private static readonly string[] _keys =
{
"some",
"key and",
"another",
"varying",
"---the --",
"keys and more",
"aa bbb",
"asasd asd ",
"asdsad asd as s",
"asdadsasa",
"23323232323",
"asdadsada sa213"
};
[Params(0, 2, 3, 5, 8, 9, 10)]
public int N { get; set; }
[Benchmark]
public void HybridDictionary()
{
var hybridDictionary = new HybridDictionary<object>();
for (var i = 0; i < N; i++)
{
hybridDictionary.Add(_keys[i], _keys);
}
foreach (var key in _keys)
{
hybridDictionary.ContainsKey(key);
}
}
[Benchmark]
public void Dictionary()
{
var dictionary = new Dictionary<string, object>();
for (var i = 0; i < N; i++)
{
dictionary.Add(_keys[i], _keys);
}
foreach (var key in _keys)
{
dictionary.ContainsKey(key);
}
}
[Benchmark]
public void StringDictionarySlim()
{
var dictionary = new StringDictionarySlim<object>();
for (var i = 0; i < N; i++)
{
dictionary[_keys[i]] =_keys;
}
foreach (var key in _keys)
{
dictionary.ContainsKey(key);
}
}
}