I never saw a resolution to this situation, so let me dive in: I am seeing the same slow execution speeds in the Arduino environment.
I used objdump to look at the code generated by the sample code from the opening post to this thread. This is my first attempt at calculating execution times for RISC-V, but by my reckoning, the entire process through the Arduino loop (including invoking loop() from the Arduino main() program) should take 59 cycles. That number assumes that SW (store word) instructions take 1 cycle. If they take 2, then it would be 61 cycles per loop. At 59 cycles per loop and a 16 MHz clock, it means that the entire arduino loop should take about 3.687 uSec. From the scope trace above (and my own measurements), the arduino loop is taking roughly 50 uSec, or about 13.5 times slower than expected.
I then instrumented the toggle code to calculate the cycle count over the two digitalWrite() calls. As expected, the first time through, the cycle count was huge at 12006 cycles no doubt due to the code getting loaded from the SPI flash into the icache. Thereafter, the execution times were much smaller. However, those execution times were not consistent. Over 100000 iterations, the min execution time was 779 cycles and the max execution time was 816 cycles. Disregarding the unexpected inconsistency, it is clear that 800 cycles is a lot larger than 60 cycles. In fact, it is about 13.3 times larger, which corresponds basically exactly with the difference between the cycle count from the assembly code as compared to the time taken in the scope trace.
Also note that if the 59 cycles count is accurate, it means that the arduino loop should be toggling at 271 KHz. This result is squarely within the range of results generated by the Eclipse test in the post directly above.
So: there is something weird with the arduino world, but not the Eclipse world. Also note, I ran my tests with interrupts disabled, so it can’t be interrupts using up cycles.
Last question: I can’t figure out how to add text formatted as code to a post. Can someone point me how at how to do that?