commit 39a1a56724d194547222093165d6f8092f22cbbe Author: Les De Ridder Date: Tue Jul 9 23:26:20 2019 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29a3ce1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.dub +docs.json +__dummy.html +docs/ +/data-structures-benchmark +data-structures-benchmark.so +data-structures-benchmark.dylib +data-structures-benchmark.dll +data-structures-benchmark.a +data-structures-benchmark.lib +data-structures-benchmark-test-* +*.exe +*.o +*.obj +*.lst diff --git a/dub.sdl b/dub.sdl new file mode 100644 index 0000000..ff9b456 --- /dev/null +++ b/dub.sdl @@ -0,0 +1,11 @@ +name "data-structures-benchmark" +description "Benchmarking code for (@nogc) data structures" +authors "lesderid" +copyright "Copyright © 2019, Les De Ridder" +license "NCSA" +dependency "emsi_containers" version="~>0.7.0" +dependency "collections" version="~>0.1.0" + +-- :/ +importPaths "/home/lesderid/repos/d/druntime/src" +sourceFiles "/home/lesderid/repos/d/druntime/generated/linux/release/64/libdruntime.a" diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..ee734cc --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,10 @@ +{ + "fileVersion": 1, + "versions": { + "collections": "0.1.0", + "emsi_containers": "0.7.0", + "mir-algorithm": "3.5.0-alpha09", + "mir-core": "0.3.5", + "stdx-allocator": "2.77.5" + } +} diff --git a/source/app.d b/source/app.d new file mode 100644 index 0000000..9047991 --- /dev/null +++ b/source/app.d @@ -0,0 +1,86 @@ +import util : make, rcarray, StdArray, StdxArray, EMSIArray; +import std.stdio : stderr, writeln; + +void testInsert(Container, int times = 100)() +{ + auto container = make!Container(); + + //debug stderr.writeln("Testing inserts on ", typeof(container).stringof); + + foreach (i; 0 .. times) + { + container ~= 42; + } + + assert(container.length == times && container[times - 1] == 42); +} + +void testInsertDelete(Container, int times = 100)() +{ + auto container = make!Container(); + + //debug stderr.writeln("Testing inserts+deletes on ", typeof(container).stringof); + + foreach (i; 0 .. times) + { + container ~= 42; + } + + foreach (i; 0 .. times) + { + static if (is(Container : StdxArray!U, U)) + { + container.forceLength(container.length - 1); + } + else static if (is(Container : EMSIArray!U, U)) + { + container.removeBack(); + } + else + { + container.length = container.length - 1; + } + } + + assert(container.length == 0); +} + +void testConcat(Container, int times = 100)() +{ + +} + +import std.meta : AliasSeq; +alias tests = AliasSeq!(testInsert, testInsertDelete, testConcat); + +void testContainers(Containers...)(int times = 100000) +{ + import std.datetime : Duration; + import std.datetime.stopwatch : benchmark; + import std.meta : staticMap; + + Duration[][string] results; + + static foreach (test; tests) + { + results[test.stringof] = benchmark!(staticMap!(test, Containers))(times); + } + + static foreach (test; tests) + { + import std.stdio : writeln; + writeln(test.stringof, ":"); + + static foreach (i, Container; Containers) + { + writeln("\t", Container.stringof, ": ", results[test.stringof][i]); + } + } +} + +void main() +{ + import std.meta : AliasSeq, staticMap; + alias tests = AliasSeq!(testInsert, testInsertDelete); + testContainers!(int[], StdArray!int, StdxArray!int, EMSIArray!int, rcarray!int); +} diff --git a/source/util.d b/source/util.d new file mode 100644 index 0000000..6e60a56 --- /dev/null +++ b/source/util.d @@ -0,0 +1,31 @@ +module util; + +public import core.experimental.array : rcarray; +public import std.container : StdArray = Array; +public import containers : EMSIArray = DynamicArray; +public import stdx.collections.array : StdxArray = Array; + +public import core.experimental.array : make; + +T make(T : U[], U)() +{ + return []; +} + +T make(T : StdArray!U, U)() +{ + enum U[] empty = []; + + import std.container : stdMake = make; + return stdMake!T(empty); +} + +T make(T : EMSIArray!U, U)() +{ + return T(); +} + +T make(T : StdxArray!U, U)() +{ + return T(); +}