LoginSignup
3
0

More than 1 year has passed since last update.

D言語でBrainfuxk処理系を作ったので、コンパイラを変えてベンチしてみる

Last updated at Posted at 2022-08-18

はじめに

処理系作成のチュートリアルでおなじみのBrainfu*kの処理系をD言語で作りました。

ベンチマーク

これを使って何かしたいので、コンパイルオプションやコンパイラを変えこの処理系をコンパイルして、マンデルブロ集合のBrainfuxkを実行し処理時間を見ます。

テストするD言語コンパイラの皆様

名前 概要
dmd 公式のD言語コンパイラです
ldc LLVMベースのD言語コンパイラです

計測用のコード

module measure;
import std.stdio,std.process,std.datetime.date,std.datetime.stopwatch;

void measure_time(string v1,string v2){
    executeShell(v1);
    writeln(v1);
    float time;
    auto sw = StopWatch(AutoStart.yes);
    sw.start();
    foreach (i; 0..10)
    {
        executeShell(v2);
    }
    auto t1 = sw.peek();
    auto temp=t1;
    auto temp2=temp.total!"seconds"/10;
    writefln("time:%d Second",temp2);
}

void main(){
    measure_time("dmd Brainfuxk-D/source/app","app Brainfuxk-D/test/Correct-Cases/mandelbrot.bf");
    measure_time("dmd -O -release -inline Brainfuxk-D/source/app","app Brainfuxk-D/test/Correct-Cases/mandelbrot.bf");
    measure_time("ldc2 Brainfuxk-D/source/app","app Brainfuxk-D/test/Correct-Cases/mandelbrot.bf");
    measure_time("ldc2 -O3 Brainfuxk-D/source/app","app Brainfuxk-D/test/Correct-Cases/mandelbrot.bf");

}

各コンパイラでコンパイルした後、10回実行して計測しています。

計測結果

実行した環境はWindows11です。

実行環境
OS: Windows11
CPU: Core i7-12700
RAM: 32GB
処理系をコンパイルしたコンパイラ Brainfuxkのマンデルブロ集合の処理時間
dmd(v2.100.0-dirty) デフォルト 68s
dmd(v2.100.0-dirty) -O -release -inline 34s
ldc2(1.30.0) デフォルト 69s
ldc2(1.30.0) -O3 30s

まとめ

dmdもldcもちゃんと最適化オプションかけるかかけないかで、だいぶ違いますね。
リリースする時は気を付けたほうがいいです。

3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0