Skip to content

Instantly share code, notes, and snippets.

@yazd

yazd/main.d Secret

Created August 8, 2015 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yazd/4826282bf51d60086bfe to your computer and use it in GitHub Desktop.
Save yazd/4826282bf51d60086bfe to your computer and use it in GitHub Desktop.
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