Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static immutable FuncNum = 10_000;
- private static immutable ClangPath = "/usr/local/bin/clang";
- void main() {
- import std.algorithm : map;
- import std.array : join;
- import std.datetime.stopwatch : benchmark;
- import std.file : write, remove;
- import std.format : format;
- import std.process : execute;
- import std.range : iota;
- import std.stdio : writeln;
- /* Build sub file */
- const subFilePath = "sub.d";
- const subFileContent = FuncNum.iota.map!(i => format!"int func%d() { return %d; }"(i,i)).join("\n");
- subFilePath.write(subFileContent);
- execute(["ldc", "-c", "sub.d"]);
- scope (exit) remove("sub.d");
- scope (exit) remove("sub.o");
- /* Build main file */
- const mainFilePath = "main.d";
- const mainFileContent = format!"import sub, std.stdio; void main() { %s }"(
- FuncNum.iota.map!(i => format!"writeln(func%d());"(i)).join("\n"));
- mainFilePath.write(mainFileContent);
- execute(["ldc", "-c", "main.d"]);
- scope (exit) remove("main.d");
- scope (exit) remove("main.o");
- /* Benchmark link time with/without gold */
- const ld = ["ldc", "main.o", "sub.o", "-linker=ld"];
- const gold = ["ldc", "main.o", "sub.o", "-linker=gold"];
- const lld = ["ldc", "main.o", "sub.o", "-linker=lld"];
- const env = ["CC" : ClangPath];
- const r = benchmark!(
- () => execute(ld, env),
- () => execute(gold, env),
- () => execute(lld, env),
- )(10);
- writeln("ld : ", r[0]);
- writeln("gold : ", r[1]);
- writeln("lld : ", r[2]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement