-
-
Save yazd/4826282bf51d60086bfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.datetime; | |
import std.conv : to; | |
import vibe.d; | |
void main() | |
{ | |
setLogLevel(LogLevel.info); | |
int count = 50_000; | |
float[] msecs; | |
msecs.length = count; | |
StopWatch sw; | |
auto settings = new HTTPClientSettings(); | |
//settings.defaultKeepAliveTimeout = 0.msecs(); | |
foreach(i; 0 .. count) | |
{ | |
auto startTime = Clock.currAppTick(); | |
logInfo("======== %s [%s] starting...", getTime(startTime), i); | |
sw.start(); | |
requestHTTP("http://127.0.0.1:8090/file.txt", | |
(scope res) { | |
}, | |
(scope res) { | |
res.bodyReader.readAll(); | |
}, | |
settings, | |
); | |
auto endTime = Clock.currAppTick(); | |
msecs[i] = sw.peek().to!("msecs", float); | |
logInfo("======== %s [%s] done, round time = %s", getTime(endTime), i, getTime(endTime - startTime)); | |
} | |
auto min = float.max; | |
auto max = float.min_normal; | |
auto sum = 0.0; | |
foreach (v; msecs) | |
{ | |
if (v < min) min = v; | |
if (v > max) max = v; | |
sum += v; | |
} | |
import std.stdio : writefln; | |
writefln("min : %07.2f ms", min); | |
writefln("max : %07.2f ms", max); | |
writefln("sum : %07.2f ms", sum); | |
writefln("mean: %07.2f ms", sum / msecs.length); | |
writefln("rps : %07.1f rps", count * 1000.0 / sum); | |
} | |
string getTime(TickDuration tick) | |
{ | |
return format("%0.3f", tick.to!("msecs", float)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment