@@ -3,4 +3,69 @@ Containers [
11+
12+ Measurements taken on a ` Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz ` with 8GB of memory.
13+ Compiled with dmd-2.068.0 using ` -O -release -inline ` flags.
14+
15+ ### Code
16+
17+ ``` d
18+ import containers.ttree;
19+ import std.container.rbtree;
20+ import containers.slist;
21+ import std.container.slist;
22+ import containers.unrolledlist;
23+ import std.experimental.allocator;
24+ import std.experimental.allocator.building_blocks.allocator_list;
25+ import std.experimental.allocator.building_blocks.region;
26+ import std.experimental.allocator.mallocator;
27+ import std.datetime;
28+ import std.stdio;
29+
30+ // For fun: change this number and watch the effect it has on the execution time
31+ alias Allocator = AllocatorList!(a => Region!Mallocator(1024 * 16), Mallocator);
32+
33+ enum NUMBER_OF_ITEMS = 500_000;
34+
35+ void testEMSIContainer(alias Container, string ContainerName)()
36+ {
37+ Allocator allocator;
38+ auto c = Container!(int, typeof(&allocator))(&allocator);
39+ StopWatch sw = StopWatch(AutoStart.yes);
40+ foreach (i; 0 .. NUMBER_OF_ITEMS)
41+ c.insert(i);
42+ sw.stop();
43+ writeln("Inserts for ", ContainerName, " finished in ",
44+ sw.peek().to!("msecs", float), " milliseconds.");
45+ }
46+
47+ void testPhobosContainer(alias Container, string ContainerName)()
48+ {
49+ static if (is(Container!int == class))
50+ auto c = new Container!int();
51+ else
52+ Container!int c;
53+ StopWatch sw = StopWatch(AutoStart.yes);
54+ foreach (i; 0 .. NUMBER_OF_ITEMS)
55+ c.insert(i);
56+ sw.stop();
57+ writeln("Inserts for ", ContainerName, " finished in ",
58+ sw.peek().to!("msecs", float), " milliseconds.");
59+ }
60+
61+ void main()
62+ {
63+ testEMSIContainer!(TTree, "TTree")();
64+ testPhobosContainer!(RedBlackTree, "RedBlackTree")();
65+
66+ testPhobosContainer!(std.container.slist.SList, "Phobos SList")();
67+ testEMSIContainer!(containers.slist.SList, "EMSI SList")();
68+
69+ testEMSIContainer!(UnrolledList, "UnrolledList")();
70+ }
71+ ```
0 commit comments