Advertisement
uaa

ASCIIART benchmark, C translated - ESP32/Arduino test

uaa
Dec 3rd, 2021
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // original BASIC code at https://www.retrobrewcomputers.org/forum/index.php?t=msg&th=201&goto=4704&#msg_4704
  2. // translated C code, CC0
  3.  
  4. #define X_MAX 79
  5. #define Y_MAX 25
  6. uint8_t result[Y_MAX][X_MAX];
  7.  
  8. inline uint32_t rsr_ccount(void)
  9. {
  10. uint32_t ccount;
  11. __asm__ volatile("rsr %0, ccount" : "=r"(ccount));
  12. return ccount;
  13. }
  14.  
  15. void display_result(void)
  16. {
  17. int x, y;
  18. const char c[] = "0123456789ABCDEF ";
  19.  
  20. for (y = 0; y < Y_MAX; y++) {
  21. for (x = 0; x < X_MAX; x++) {
  22. Serial.print(c[result[y][x]]);
  23. }
  24. Serial.print('\n');
  25. }
  26. }
  27.  
  28. void benchmark(void)
  29. {
  30. int x, y, i;
  31. float a, b, ca, cb, t;
  32.  
  33. for (y = -12; y <= 12; y++) {
  34. for (x = -39; x <= 39; x++) {
  35. a = ca = x * 0.0458;
  36. b = cb = y * 0.08333;
  37.  
  38. for (i = 0; i <= 15; i++) {
  39. t = (a * a) - (b * b) + ca;
  40. b = (2 * a * b) + cb;
  41. a = t;
  42.  
  43. if ((a * a + b * b) > 4)
  44. break;
  45. }
  46. result[y + 12][x + 39] = i;
  47. }
  48. }
  49.  
  50. return;
  51. }
  52.  
  53. void setup() {
  54. uint32_t before, after;
  55.  
  56. Serial.begin(38400);
  57. Serial.print('\n');
  58.  
  59. before = rsr_ccount();
  60. delay(1000);
  61. after = rsr_ccount();
  62. Serial.print(after - before);
  63. Serial.print('\n');
  64.  
  65. before = rsr_ccount();
  66. benchmark();
  67. after = rsr_ccount();
  68. Serial.print(after - before);
  69. Serial.print('\n');
  70.  
  71. before = micros();
  72. benchmark();
  73. after = micros();
  74. Serial.print(after - before);
  75. Serial.print('\n');
  76.  
  77.  
  78. display_result();
  79. }
  80.  
  81. void loop() {
  82. // do nothing
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement