[MemoryDiagnoser]
public class ExtremelySimpleDictionaryBenchmark
{
private readonly List _keys = new();
private readonly Dictionary _dict = new ();
private readonly ConcurrentDictionary _concurrentDict = new ();
private const int DictionarySize = 300;
private const string Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static string Generate(int length, Random random)
{
var result = new char[length];
for (var i = 0; i < length; i++)
result[i] = Alphabet[random.Next(Alphabet.Length)];
return new string(result);
}
[GlobalSetup]
public void Setup()
{
var rnd = new Random();
for (var i = 0; i < DictionarySize; i++)
{
var key = Generate(6, rnd);
var count = rnd.Next(1000);
_dict[key] = count;
_concurrentDict[key] = count;
_keys.Add(key);
}
}
[Benchmark(Baseline = true)]
public int Dictionary()
{
// variable res is used to avoid dead code elimination
var res = 0;
for (var index = 0; index < _keys.Count; index++)
if(_dict.TryGetValue(_keys[index], out var value))
res += value;
return res;
}
[Benchmark]
public int ConcurrentDictionary()
{
// variable res is used to avoid dead code elimination
var res = 0;
for (var index = 0; index < _keys.Count; index++)
if(_concurrentDict.TryGetValue(_keys[index], out var value))
res += value;
return res;
}
}
< /code>
Es führt zu wirklich seltsamen Ergebnissen. ConcurrentDictionary.trygetValue
Beats Dictionary.tryGetValue in Bezug auf die Leistung. Ich habe die folgenden Ergebnisse: < /p>
Methode < /th>
Wörterbuch < /td>
2,055 US < /td>
-< /td>
na < /td>
< /tr>
< /tbody> < /> < /table> < /div>
< /tbody>
< /table> < /div>
bnchmark wurde auf dem banchmark .Net core 8, core 11. /> Wie können solche Ergebnisse erklärt werden? < /P>
Ich habe einen wirklich einfachen Benchmark zum Messen und Vergleich der Leistung von Dictionary und gleichzeitiger Verfassung : [code][MemoryDiagnoser] public class ExtremelySimpleDictionaryBenchmark { private readonly List _keys = new(); private readonly Dictionary _dict = new (); private readonly ConcurrentDictionary _concurrentDict = new ();
private static string Generate(int length, Random random) { var result = new char[length]; for (var i = 0; i < length; i++) result[i] = Alphabet[random.Next(Alphabet.Length)]; return new string(result); }
[GlobalSetup] public void Setup() { var rnd = new Random(); for (var i = 0; i < DictionarySize; i++) { var key = Generate(6, rnd); var count = rnd.Next(1000); _dict[key] = count; _concurrentDict[key] = count; _keys.Add(key); } }
[Benchmark(Baseline = true)] public int Dictionary() { // variable res is used to avoid dead code elimination var res = 0; for (var index = 0; index < _keys.Count; index++) if(_dict.TryGetValue(_keys[index], out var value)) res += value; return res; }
[Benchmark] public int ConcurrentDictionary() { // variable res is used to avoid dead code elimination var res = 0; for (var index = 0; index < _keys.Count; index++) if(_concurrentDict.TryGetValue(_keys[index], out var value)) res += value; return res; } } < /code> Es führt zu wirklich seltsamen Ergebnissen. ConcurrentDictionary.trygetValue [/code] Beats Dictionary.tryGetValue in Bezug auf die Leistung. Ich habe die folgenden Ergebnisse: < /p>
Methode < /th>
Wörterbuch < /td> 2,055 US < /td> -< /td> na < /td> < /tr> < /tbody> < /> < /table> < /div> < /tbody> < /table> < /div> bnchmark wurde auf dem banchmark .Net core 8, core 11. /> Wie können solche Ergebnisse erklärt werden? < /P>
Gemäß CPPReference sollen die meisten Verwendungen des volatilen Schlüsselworts in C ++ 20 veraltet sein. Was ist der Nachteil von flüchtigem ? Und was ist die alternative Lösung, wenn es nicht...
Ich habe versucht, die Kosten einer Indirektion zu messen, da das Stapeln von Indirektionen übereinander die Leistung speziell abbauen sollte. /> Virtuelle Funktionsaufruf. Code
#include
#include...
Ich habe ein Wörterbuch mit mehreren Einträgen
res = {'status': 'done', 'nextLogId': 'AQAAAXb', 'logs': [{'content': {'service': 't2pipeline', 'tags': , 'timestamp': '2021-01-05T05:25:03.416Z',...
Bei der Verwendung der Funktion Torch.fft.rfft von PyTorch habe ich festgestellt, dass die Angabe eines Ausgabetensors mithilfe des Parameters out langsamer ist, als die Ausgabe intern von PyTorch...