Preliminary main mbed library for nexpaq development
Diff: libraries/tests/mbed/stdio_benchmark/main.cpp
- Revision:
- 0:6c56fb4bc5f0
diff -r 000000000000 -r 6c56fb4bc5f0 libraries/tests/mbed/stdio_benchmark/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libraries/tests/mbed/stdio_benchmark/main.cpp Fri Nov 04 20:27:58 2016 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" + +#if !DEVICE_LOCALFILESYSTEM + #error [NOT_SUPPORTED] LocalFileSystem not supported +#endif + +#define TEST_STDIO 0 + +int main() { + printf("\r\n\r\n*** Start of memory write test (2K bytes) ***\r\n"); + + // dummy data + char buf[2048]; + int index = 0; + for (index = 0; index < 2048; index++) { + buf[index] = ~index & 0xFF; + } + + // Run the timed write test + float starttime, duration; + Timer t; + t.start(); + starttime = t.read(); + +#if TEST_STDIO + LocalFileSystem local("local"); + FILE *fp = fopen("/local/test.dat", "w"); + fwrite(buf, sizeof(buf[0]), sizeof(buf)/sizeof(buf[0]), fp); + fclose(fp); +#else + FILEHANDLE fh = local_file_open("test.dat", O_WRONLY); + LocalFileHandle lfh(fh); + lfh.write(buf, sizeof(buf)); + lfh.close(); +#endif + + duration = t.read() - starttime; + printf("Write completed in %.2f seconds. Average throughput = %.0f bytes/second.\r\n", duration, 2048/duration); +}