From: Avery Pennarun Date: Wed, 30 Dec 2009 06:08:27 +0000 (-0500) Subject: datagen.c: a quick program to generate a repeatable series of bytes. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=a9a163f748c140ab5e4fc5131f74cc207e0c65fc;p=packages%2Fb%2Fbup.git datagen.c: a quick program to generate a repeatable series of bytes. Useful for testing. Note that we *don't* see the random number generator, so every time you generate the bytes, you get the same sequence. This is also vastly faster than /dev/urandom, since it doesn't try to be cryptographically secure. It generates about 200 megs/sec on my computer, which is much faster than a disk and thus useful for testing the speed of hashsplit. --- diff --git a/.gitignore b/.gitignore index bd5c389..f0b96cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ hsplit hjoin hashsplit hashjoin +datagen *.o *~ tags[12] diff --git a/Makefile b/Makefile index 21c176d..081bd4d 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,12 @@ CFLAGS=-Wall -g -Werror default: all -all: hashsplit hashjoin +all: hashsplit hashjoin datagen hashsplit: hashsplit.o +datagen: datagen.o + hashjoin: hashjoin.sh test: hashsplit hashjoin @@ -30,5 +32,5 @@ test: hashsplit hashjoin gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS) clean: - rm -f *.o *~ hashsplit hashjoin hsplit hjoin \ + rm -f *.o *~ hashsplit hashjoin hsplit hjoin datagen \ out[12] tags[12] .*~ diff --git a/datagen.c b/datagen.c new file mode 100644 index 0000000..946f7c4 --- /dev/null +++ b/datagen.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + if (argc != 2) + { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + int kbytes = atoi(argv[1]); + uint32_t buf[1024/4]; + int i; + + for (; kbytes > 0; kbytes--) + { + for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++) + buf[i] = random(); + write(1, buf, sizeof(buf)); + if (!(kbytes%1024)) + fprintf(stderr, "."); + } + + return 0; +}