1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5NanoC6、フィボナッチ数列で遊ぶ(UNO R3より52倍速い)

Last updated at Posted at 2024-11-29

参考

x 過去ログを見よ
x 引用しました。

いろいろ
M5NanoC6は、RISC-V、クロック160MHzでほぼシングルCPUため、M5StamS3と比べると遅いと予想されます。

目的
整数のベンチマークする

結果

1回目 なぜかおかしい

o_coq661.jpg

2回目 DEBUGを外してみる 正しい (最適化が効いてドコモ値を使っていないからか)

o_coq662.jpg

3回目 最後の値を出力してみる


    }
  }
  end_time = millis();
  time = end_time - start_time;
  Serial.print("END Value:");
  Serial.println(x); //最後の値の出力
  Serial.print("StartTime:");



たぶん、正しい

o_coq663.jpg

比較 約52倍速い

M5NanoC6 約336ms(0.3秒)

Arduino UNO 3 約17542ms(1.8秒)

クロックで10倍、レジスター長で4倍だから、だいたいあっている!!

o_coq667.jpg

プログラム


//値が100,000を超えるまでのフィボナッチ数列を生成する作業を500,000回繰り返すのに要した時間を計測する。
#define DEBUG 0
void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.print("START");
  for(int i = 0;i < 9;i++){
    Serial.print('.');
    delay(500);
  }
  Serial.println();
}
void loop() {
  unsigned long x;
  unsigned long prevx;
  unsigned long temp;
  unsigned long start_time, end_time;
  unsigned long time;
  start_time = millis();
  for (unsigned long a = 0; a < 500000; a++) {
    x = 1;
    prevx = 0;
    while (x < 100000) {
      temp = x;
      x = prevx + x;
      prevx = temp;
#if DEBUG
      Serial.println(x);
#endif
    }
  }
  end_time = millis();
  time = end_time - start_time;
  Serial.print("END Value:");
  Serial.println(x); //最後の値の出力
  Serial.print("StartTime:");
  Serial.print(start_time);
  Serial.print(" EndTime:");
  Serial.print(end_time);
  Serial.print(" Time:");
  Serial.println(time);
  delay(1000);  //1秒待機
}


1
1
4

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?