Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. private static immutable FuncNum = 10_000;
  2. private static immutable ClangPath = "/usr/local/bin/clang";
  3.  
  4. void main() {
  5. import std.algorithm : map;
  6. import std.array : join;
  7. import std.datetime.stopwatch : benchmark;
  8. import std.file : write, remove;
  9. import std.format : format;
  10. import std.process : execute;
  11. import std.range : iota;
  12. import std.stdio : writeln;
  13.  
  14. /* Build sub file */
  15. const subFilePath = "sub.d";
  16. const subFileContent = FuncNum.iota.map!(i => format!"int func%d() { return %d; }"(i,i)).join("\n");
  17. subFilePath.write(subFileContent);
  18. execute(["ldc", "-c", "sub.d"]);
  19. scope (exit) remove("sub.d");
  20. scope (exit) remove("sub.o");
  21.  
  22. /* Build main file */
  23. const mainFilePath = "main.d";
  24. const mainFileContent = format!"import sub, std.stdio; void main() { %s }"(
  25. FuncNum.iota.map!(i => format!"writeln(func%d());"(i)).join("\n"));
  26. mainFilePath.write(mainFileContent);
  27. execute(["ldc", "-c", "main.d"]);
  28. scope (exit) remove("main.d");
  29. scope (exit) remove("main.o");
  30.  
  31. /* Benchmark link time with/without gold */
  32. const ld = ["ldc", "main.o", "sub.o", "-linker=ld"];
  33. const gold = ["ldc", "main.o", "sub.o", "-linker=gold"];
  34. const lld = ["ldc", "main.o", "sub.o", "-linker=lld"];
  35. const env = ["CC" : ClangPath];
  36.  
  37. const r = benchmark!(
  38. () => execute(ld, env),
  39. () => execute(gold, env),
  40. () => execute(lld, env),
  41. )(10);
  42.  
  43. writeln("ld : ", r[0]);
  44. writeln("gold : ", r[1]);
  45. writeln("lld : ", r[2]);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement