1919
2020module opendal ;
2121
22- version (D_BetterC )
23- {
24- version (LDC )
25- {
26- pragma (LDC_no_moduleinfo);
27- pragma (LDC_no_typeinfo);
28- }
29- }
30-
3122public import opendal.operator;
3223
3324version (unittest )
3425{
3526 @(" Test basic Operator creation" )
36- unittest
27+ @safe unittest
3728 {
3829 /* Initialize a operator for "memory" backend, with no options */
39- auto options = new OperatorOptions();
30+ OperatorOptions options = new OperatorOptions();
4031 Operator op = Operator(" memory" , options);
4132
4233 /* Prepare some data to be written */
@@ -48,10 +39,85 @@ version (unittest)
4839 /* We can read it out, make sure the data is the same */
4940 auto read_bytes = op.read(" /testpath" );
5041 assert (read_bytes.length == 24 );
42+ assert (cast (string )read_bytes.idup == data);
43+ }
5144
52- /* Lets print it out */
45+ @(" Benchmark parallel and normal functions" )
46+ @safe unittest
47+ {
48+ import std.exception : assertNotThrown;
49+ import std.file : tempDir;
50+ import std.path : buildPath;
51+ import std.datetime.stopwatch : StopWatch;
5352 import std.stdio : writeln;
5453
55- writeln(cast (string )read_bytes.idup);
54+ auto options = new OperatorOptions();
55+ options.set(" root" , tempDir);
56+ auto op = Operator(" fs" , options, true );
57+
58+ auto testPath = buildPath(tempDir, " benchmark_test.txt" );
59+ auto testData = cast (ubyte [])" Benchmarking OpenDAL async and normal functions" .dup ;
60+
61+ // Benchmark write operations
62+ StopWatch sw;
63+
64+ sw.start();
65+ assertNotThrown(op.write(testPath, testData));
66+ sw.stop();
67+ auto normalWriteTime = sw.peek();
68+
69+ sw.reset();
70+ sw.start();
71+ assertNotThrown(op.writeParallel(testPath, testData));
72+ sw.stop();
73+ auto parallelWriteTime = sw.peek();
74+
75+ // Benchmark read operations
76+ sw.reset();
77+ sw.start();
78+ auto normalReadData = op.read(testPath);
79+ sw.stop();
80+ auto normalReadTime = sw.peek();
81+
82+ sw.reset();
83+ sw.start();
84+ auto parallelReadData = op.readParallel(testPath);
85+ sw.stop();
86+ auto parallelReadTime = sw.peek();
87+
88+ // Benchmark list operations
89+ sw.reset();
90+ sw.start();
91+ op.list(tempDir);
92+ sw.stop();
93+ auto normalListTime = sw.peek();
94+
95+ sw.reset();
96+ sw.start();
97+ op.listParallel(tempDir);
98+ sw.stop();
99+ auto parallelListTime = sw.peek();
100+
101+ // Print benchmark results
102+ writeln(" Write benchmark:" );
103+ writeln(" Normal: " , normalWriteTime);
104+ writeln(" Parallel: " , parallelWriteTime);
105+
106+ writeln(" Read benchmark:" );
107+ writeln(" Normal: " , normalReadTime);
108+ writeln(" Parallel: " , parallelReadTime);
109+
110+ writeln(" List benchmark:" );
111+ writeln(" Normal: " , normalListTime);
112+ writeln(" Parallel: " , parallelListTime);
113+
114+ // Verify data integrity
115+ assert (normalReadData == testData);
116+ assert (parallelReadData == testData);
117+
118+ // Clean up
119+ op.removeObject(testPath);
120+ assert (! op.exists(testPath));
56121 }
122+
57123}
0 commit comments