Initial commit

This commit is contained in:
Les De Ridder 2019-07-09 23:26:20 +02:00
commit 39a1a56724
5 changed files with 153 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -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

11
dub.sdl Normal file
View File

@ -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"

10
dub.selections.json Normal file
View File

@ -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"
}
}

86
source/app.d Normal file
View File

@ -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);
}

31
source/util.d Normal file
View File

@ -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();
}