]> arthur.barton.de Git - bup.git/commitdiff
datagen.c: a quick program to generate a repeatable series of bytes.
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 30 Dec 2009 06:08:27 +0000 (01:08 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 30 Dec 2009 06:08:27 +0000 (01:08 -0500)
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.

.gitignore
Makefile
datagen.c [new file with mode: 0644]

index bd5c38958ecbe3fc79899fcde19c1e7ae55ad225..f0b96cfd60cb293727f831814388db0096a54b3b 100644 (file)
@@ -2,6 +2,7 @@ hsplit
 hjoin
 hashsplit
 hashjoin
+datagen
 *.o
 *~
 tags[12]
index 21c176dd1f29a6a6d5e4554f2df6e3d62844fed0..081bd4d77adeff0b8dec9f00eff1dd8fb0564371 100644 (file)
--- 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 (file)
index 0000000..946f7c4
--- /dev/null
+++ b/datagen.c
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+int main(int argc, char **argv)
+{
+    if (argc != 2)
+    {
+       fprintf(stderr, "usage: %s <kbytes>\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;
+}