1 module app;
2 
3 import std.conv;
4 import std.datetime.stopwatch;
5 import std.format;
6 import std.getopt;
7 import std.stdio;
8 import std.traits;
9 
10 static string _gitversion = import("git_describe.txt");
11 
12 bool argVerbose = false;
13 
14 /** Combined test and benchmark runner for phobos digests.
15  * Param:
16  *   args - string array with commandline args
17  */
18 int main(string[] args)
19 {
20 	enum TestsEnum { all, crc32, crc64ecma, crc64iso, xxh32, xxh64, xxh3_64, xxh3_128, murmur32, murmur128, md5 }
21 	bool writeCSV = false;
22 	int argTimeLimit = 3 * 60;
23 
24 	TestsEnum tests = TestsEnum.all;
25 	try {
26 		auto helpInformation = getopt(
27 			args,
28 			"verbose|v", "Verbose outputs (WIP)", &argVerbose,
29 			"test|t", "Select a test out of " ~ format("%s", [EnumMembers!TestsEnum]), &tests,
30 			"max-duration", "Set time limit for each test (seconds)", &argTimeLimit,
31 			"writecsv|w", "Write CSV files", &writeCSV);
32 
33 		if (helpInformation.helpWanted)
34 		{
35 			defaultGetoptPrinter("Some information about the program.",
36 				helpInformation.options);
37 			return 0;
38 		}
39 	} catch (std.getopt.GetOptException goe)
40 	{
41 		writeln(goe.msg);
42 		return 1;
43 	} catch (std.conv.ConvException ce)
44 	{
45 		writeln(ce.msg);
46 		return 1;
47 	}
48 	int rc = 0;
49 	auto sw = StopWatch(AutoStart.no);
50 	sw.reset;
51 	sw.start;
52 	writeln("A benchmark utility for the phobos digests.\n");
53 	writeln("Build is ", _gitversion);
54 	writeln("Time Limit per test is ", argTimeLimit);
55 	if (tests == TestsEnum.all || tests == TestsEnum.crc32)
56 	{
57 		import test_crc32 : test_crc32;
58 
59 		rc += test_crc32(argTimeLimit, writeCSV);
60 	}
61 	if (tests == TestsEnum.all || tests == TestsEnum.crc64ecma)
62 	{
63 		import test_crc64ecma : test_crc64ecma;
64 
65 		rc += test_crc64ecma(argTimeLimit, writeCSV);
66 	}
67 	if (tests == TestsEnum.all || tests == TestsEnum.crc64iso)
68 	{
69 		import test_crc64iso : test_crc64iso;
70 
71 		rc += test_crc64iso(argTimeLimit, writeCSV);
72 	}
73 	if (tests == TestsEnum.all || tests == TestsEnum.xxh32)
74 	{
75 		import test_xxh32 : test_xxh32;
76 
77 		rc += test_xxh32(argTimeLimit, writeCSV);
78 	}
79 	if (tests == TestsEnum.all || tests == TestsEnum.xxh64)
80 	{
81 		import test_xxh64 : test_xxh64;
82 
83 		rc += test_xxh64(argTimeLimit, writeCSV);
84 	}
85 	if (tests == TestsEnum.all || tests == TestsEnum.xxh3_64)
86 	{
87 		import test_xxh3_64 : test_xxh3_64;
88 
89 		rc += test_xxh3_64(argTimeLimit, writeCSV);
90 	}
91 	if (tests == TestsEnum.all || tests == TestsEnum.xxh3_128)
92 	{
93 		import test_xxh3_128 : test_xxh3_128;
94 
95 		rc += test_xxh3_128(argTimeLimit, writeCSV);
96 	}
97 	if (tests == TestsEnum.all || tests == TestsEnum.murmur32)
98 	{
99 		import test_murmur32 : test_mm32;
100 
101 		rc += test_mm32(argTimeLimit, writeCSV);
102 	}
103 	if (tests == TestsEnum.all || tests == TestsEnum.murmur128)
104 	{
105 		import test_murmur128 : test_mm128;
106 
107 		rc += test_mm128(argTimeLimit, writeCSV);
108 	}
109 	if (tests == TestsEnum.all || tests == TestsEnum.md5)
110 	{
111 		import test_md5 : test_md5;
112 
113 		rc += test_md5(argTimeLimit, writeCSV);
114 	}
115 	sw.stop;
116 	writefln("Total test duration: %s", sw.peek);
117 	return rc;
118 }