Created
July 19, 2019 05:01
-
-
Save leotada/986dcbc1176005a6a401d73a0fe4408c to your computer and use it in GitHub Desktop.
Fibonacci Vibe.d multithread benchmark
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 core.thread; | |
import vibe.vibe; | |
import std.stdio; | |
int fib(int n) | |
{ | |
if (n <= 1) | |
return n; | |
return fib(n - 1) + fib(n - 2); | |
} | |
void handleRequest(HTTPServerRequest req, HTTPServerResponse res) | |
{ | |
if (req.path == "/bench") | |
{ | |
res.writeJsonBody(["message": fib(15)]); | |
} | |
} | |
void runServer() | |
{ | |
auto settings = new HTTPServerSettings; | |
settings.options |= HTTPServerOption.reusePort; | |
settings.port = 8000; | |
settings.bindAddresses = ["0.0.0.0"]; | |
listenHTTP(settings, &handleRequest); | |
} | |
void main() | |
{ | |
writefln("Master %d is running", getpid()); | |
setupWorkerThreads(logicalProcessorCount); | |
runWorkerTaskDist(&runServer); | |
runApplication(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment