private unsafe void InsertAndReadAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { var watch = Stopwatch.StartNew(); for (var i = first; i < first + count; i++) { ulong val = 0; if (!map.TryAdd(keys.GetAt(i - offset), i)) { throw new Exception("Failed to insert " + i + ", offset from " + offset); } if (!map.TryGetValue(keys.GetAt(i - offset), ref val)) { throw new Exception("Failed to get at " + i + ", offset from " + offset); } if (val != i) { throw new Exception("Failed to validate at " + i + ", offset from " + offset); } //Console.WriteLine("Added {0} at {1}", val, i); } watch.Stop(); //Console.WriteLine("Elapsed: {0}, for {1}, {2}", watch.ElapsedMilliseconds, first, count); }
private unsafe void BasicMemoryAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { for (var k = first; k < first + count; k++) { using (var map2 = new ConcurrentHashmapOfKeys(_pool)) { map2.TryAdd(keys.GetAt(0), 0); } } //var b = stackalloc void*[(int)100000]; //for (var k = 0; k < 10000000000; k++) //{ // for (var i = 0; i < 100000; i++) // { // b[i] = _pool.Alloc((ulong) i % 10000); // } // for (var i = 0; i < 100000; i++) // { // _pool.Free(b[i]); // } //} }
unsafe ExpandableArrayOfKeys GenerateKeys(ulong count) { var result = new ExpandableArrayOfKeys(_pool); result.EnsureCapacity(count); var key = new byte[10]; for (ulong i = 1; i <= count; i++) { var val = i; byte pos = 1; while (val != 0) { key[pos++] = (byte)val; val >>= 8; } key[0] = (byte)(pos-1); //result[i-1] = key; if (!result.TrySetAt((int)i - 1, key)) { throw new Exception("Failed to set a key element at " + (i-1)); } } for (ulong i = 1; i <= count; i++) { var storedKey = result.GetAt(i-1); var val = i; byte pos = 1; while (val != 0) { key[pos++] = (byte)val; val >>= 8; } key[0] = (byte)(pos-1); if (storedKey[0] != key[0]) { throw new Exception("Length prefix broken at " + (i - 1)); } for (var j = 0; j <= key[0]; j++) { //Console.Write(storedKey[j]); //Console.Write(','); if (storedKey[j] != key[j]) { throw new Exception("Data broken at " + (i - 1) + ", offset " + j); } } //Console.WriteLine(); } return result; }
private unsafe void ReadAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { var watch = Stopwatch.StartNew(); for (var k = 0; k < 10000; k++ ) for (var i = first; i < first + count; i++) { ulong val = 0; if (!map.TryGetValue(keys.GetAt(i - offset), ref val)) { throw new Exception("Failed to get at " + i + ", offset from " + offset); } if (val != i) { throw new Exception("Failed to validate at " + i + ", offset from " + offset); } //Console.WriteLine("Added {0} at {1}", val, i); } watch.Stop(); //Console.WriteLine("Elapsed: {0}, for {1}, {2}", watch.ElapsedMilliseconds, first, count); }
unsafe ExpandableArrayOfKeys GenerateKeys(ulong count) { var result = new ExpandableArrayOfKeys(_pool); result.EnsureCapacity(count); var key = new byte[10]; for (ulong i = 1; i <= count; i++) { var val = i; byte pos = 1; while (val != 0) { key[pos++] = (byte)val; val >>= 8; } key[0] = (byte)(pos - 1); //result[i-1] = key; if (!result.TrySetAt((int)i - 1, key)) { throw new Exception("Failed to set a key element at " + (i - 1)); } } for (ulong i = 1; i <= count; i++) { var storedKey = result.GetAt(i - 1); var val = i; byte pos = 1; while (val != 0) { key[pos++] = (byte)val; val >>= 8; } key[0] = (byte)(pos - 1); if (storedKey[0] != key[0]) { throw new Exception("Length prefix broken at " + (i - 1)); } for (var j = 0; j <= key[0]; j++) { //Console.Write(storedKey[j]); //Console.Write(','); if (storedKey[j] != key[j]) { throw new Exception("Data broken at " + (i - 1) + ", offset " + j); } } //Console.WriteLine(); } return(result); }