Simple program to determine Ethernet Rx bandwidth
Revision 0:35df02818f6d, committed 2011-02-25
- Comitter:
- simon
- Date:
- Fri Feb 25 16:03:40 2011 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 35df02818f6d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 25 16:03:40 2011 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "Ethernet.h" + +Ethernet eth; + +#define NPACKETS 100000 + +int main() { + printf("Hello Ethernet Rx Benchmark!\n"); + + char buffer[0x600]; + int size = 0; + + char buf[6] = {0}; + eth.address(buf); + printf("mbed MAC: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + + while(!eth.link()); + + printf("Waiting for %d packets...\n", NPACKETS); + + Timer t; + int n = 0; + for(int i=0; i<NPACKETS; i++) { + do { + size = eth.receive(); + } while(size <= 0); + eth.read(buffer, size); + n += size; + } + t.stop(); + printf("Time = %.2f seconds\n", t.read()); + + float bw = n * 8 / t.read(); + printf("bandwidth = %.2f kbps\n", bw / 1024.0); + +}