Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Last active April 28, 2019 03:06
Show Gist options
  • Save ShigekiKarita/9bb8a1532ca114e7f7a346e2a7fedb99 to your computer and use it in GitHub Desktop.
Save ShigekiKarita/9bb8a1532ca114e7f7a346e2a7fedb99 to your computer and use it in GitHub Desktop.
Comparison ld and gold
private static immutable FuncNum = 10_000;
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(["dmd", "-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(["dmd", "-c", "main.d"]);
scope (exit) remove("main.d");
scope (exit) remove("main.o");
/* Benchmark link time with/without gold */
{
const ld = ["dmd", "main.o", "sub.o"];
const gold = ["dmd", "main.o", "sub.o", "-L-fuse-ld=gold"];
// (ubuntu 18.04) sudo apt-get install lld-7
const lld = ["dmd", "main.o", "sub.o", "-L-fuse-ld=ld.lld-7"];
const r = benchmark!(
() => execute(ld),
() => execute(gold),
() => execute(lld),
)(10);
writeln("dmd->ld : ", r[0]);
writeln("dmd->gold : ", r[1]);
writeln("dmd->lld : ", r[2]);
}
{
const ld = ["ldc2", "main.o", "sub.o", "--linker=ld"];
const gold = ["ldc2", "main.o", "sub.o", "--linker=gold"];
const lld = ["ldc2", "main.o", "sub.o", "--linker=lld"];
const r = benchmark!(
() => execute(ld),
() => execute(gold),
() => execute(lld),
)(10);
writeln("ldc->ld : ", r[0]);
writeln("ldc->gold : ", r[1]);
writeln("ldc->lld : ", r[2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment