stew

a monorepo of some sort
git clone git://git.nsmpr.xyz/stew.git
Log | Files | Refs

bps.c (394B)


      1 /*
      2 	bps - bytes per second
      3 */
      4 #include <u.h>
      5 #include <libc.h>
      6 
      7 #define BSize 8192
      8 
      9 void
     10 main(void)
     11 {
     12 	char *buf = malloc(BSize);
     13 	long n;
     14 	vlong start = nsec(), cur, bytes = 0;;
     15 	for (;;) {
     16 		n = read(0, buf, BSize);
     17 		bytes += n;
     18 		write(1, buf, n);
     19 		if (n <= 0) return;
     20 		cur = nsec();
     21 		if (cur - start > 1000000000) {
     22 			fprint(2, "%lld\n", bytes);
     23 			start = cur;
     24 			bytes = 0;
     25 		}
     26 	}
     27 }