nostrdb: pull latest, adding flatcc and lmdb
This commit is contained in:
1
nostrdb/flatcc/support/README
Normal file
1
nostrdb/flatcc/support/README
Normal file
@@ -0,0 +1 @@
|
||||
support files mainly used for testing
|
||||
38
nostrdb/flatcc/support/cdump.h
Normal file
38
nostrdb/flatcc/support/cdump.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef CDUMP_H
|
||||
#define CDUMP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Generates a constant a C byte array. */
|
||||
static void cdump(const char *name, void *addr, size_t len, FILE *fp) {
|
||||
unsigned int i;
|
||||
unsigned char *pc = (unsigned char*)addr;
|
||||
|
||||
// Output description if given.
|
||||
name = name ? name : "dump";
|
||||
fprintf(fp, "const unsigned char %s[] = {", name);
|
||||
|
||||
// Process every byte in the data.
|
||||
for (i = 0; i < (unsigned int)len; i++) {
|
||||
// Multiple of 16 means new line (with line offset).
|
||||
|
||||
if ((i % 16) == 0) {
|
||||
fprintf(fp, "\n ");
|
||||
} else if ((i % 8) == 0) {
|
||||
fprintf(fp, " ");
|
||||
}
|
||||
|
||||
fprintf(fp, " 0x%02x,", pc[i]);
|
||||
}
|
||||
fprintf(fp, "\n};\n");
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CDUMP_H */
|
||||
73
nostrdb/flatcc/support/elapsed.h
Normal file
73
nostrdb/flatcc/support/elapsed.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef ELAPSED_H
|
||||
#define ELAPSED_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Based on http://stackoverflow.com/a/8583395 */
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/time.h>
|
||||
static double elapsed_realtime(void) { // returns 0 seconds first time called
|
||||
static struct timeval t0;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
if (!t0.tv_sec)
|
||||
t0 = tv;
|
||||
return (double)(tv.tv_sec - t0.tv_sec) + (double)(tv.tv_usec - t0.tv_usec) / 1e6;
|
||||
}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#ifndef FatalError
|
||||
#define FatalError(s) do { perror(s); exit(-1); } while(0)
|
||||
#endif
|
||||
static double elapsed_realtime(void) { // granularity about 50 microsecs on my machine
|
||||
static LARGE_INTEGER freq, start;
|
||||
LARGE_INTEGER count;
|
||||
if (!QueryPerformanceCounter(&count))
|
||||
FatalError("QueryPerformanceCounter");
|
||||
if (!freq.QuadPart) { // one time initialization
|
||||
if (!QueryPerformanceFrequency(&freq))
|
||||
FatalError("QueryPerformanceFrequency");
|
||||
start = count;
|
||||
}
|
||||
return (double)(count.QuadPart - start.QuadPart) / freq.QuadPart;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end Based on stackoverflow */
|
||||
|
||||
static int show_benchmark(const char *descr, double t1, double t2, size_t size, int rep, const char *reptext)
|
||||
{
|
||||
double tdiff = t2 - t1;
|
||||
double nstime;
|
||||
|
||||
printf("operation: %s\n", descr);
|
||||
printf("elapsed time: %.3f (s)\n", tdiff);
|
||||
printf("iterations: %d\n", rep);
|
||||
printf("size: %lu (bytes)\n", (unsigned long)size);
|
||||
printf("bandwidth: %.3f (MB/s)\n", (double)rep * (double)size / 1e6 / tdiff);
|
||||
printf("throughput in ops per sec: %.3f\n", rep / tdiff);
|
||||
if (reptext && rep != 1) {
|
||||
printf("throughput in %s ops per sec: %.3f\n", reptext, 1 / tdiff);
|
||||
}
|
||||
nstime = tdiff * 1e9 / rep;
|
||||
if (nstime < 1000) {
|
||||
printf("time per op: %.3f (ns)\n", nstime);
|
||||
} else if (nstime < 1e6) {
|
||||
printf("time per op: %.3f (us)\n", nstime / 1000);
|
||||
} else if (nstime < 1e9) {
|
||||
printf("time per op: %.3f (ms)\n", nstime / 1e6);
|
||||
} else {
|
||||
printf("time per op: %.3f (s)\n", nstime / 1e9);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ELAPSED_H */
|
||||
47
nostrdb/flatcc/support/hexdump.h
Normal file
47
nostrdb/flatcc/support/hexdump.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef HEXDUMP_H
|
||||
#define HEXDUMP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Based on: http://stackoverflow.com/a/7776146 */
|
||||
static void hexdump(const char *desc, const void *addr, size_t len, FILE *fp) {
|
||||
unsigned int i;
|
||||
unsigned char buf[17];
|
||||
const unsigned char *pc = (const unsigned char*)addr;
|
||||
|
||||
/* Output description if given. */
|
||||
if (desc != NULL) fprintf(fp, "%s:\n", desc);
|
||||
|
||||
for (i = 0; i < (unsigned int)len; i++) {
|
||||
|
||||
if ((i % 16) == 0) {
|
||||
if (i != 0) fprintf(fp, " |%s|\n", buf);
|
||||
fprintf(fp, "%08x ", i);
|
||||
} else if ((i % 8) == 0) {
|
||||
fprintf(fp, " ");
|
||||
}
|
||||
fprintf(fp, " %02x", pc[i]);
|
||||
if ((pc[i] < 0x20) || (pc[i] > 0x7e)) {
|
||||
buf[i % 16] = '.';
|
||||
} else {
|
||||
buf[i % 16] = pc[i];
|
||||
}
|
||||
buf[(i % 16) + 1] = '\0';
|
||||
}
|
||||
if (i % 16 <= 8 && i % 16 != 0) fprintf(fp, " ");
|
||||
while ((i % 16) != 0) {
|
||||
fprintf(fp, " ");
|
||||
i++;
|
||||
}
|
||||
fprintf(fp, " |%s|\n", buf);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEXDUMP_H */
|
||||
66
nostrdb/flatcc/support/readfile.h
Normal file
66
nostrdb/flatcc/support/readfile.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef READFILE_H
|
||||
#define READFILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static char *readfile(const char *filename, size_t max_size, size_t *size_out)
|
||||
{
|
||||
FILE *fp;
|
||||
long k;
|
||||
size_t size, pos, n, _out;
|
||||
char *buf;
|
||||
|
||||
size_out = size_out ? size_out : &_out;
|
||||
|
||||
fp = fopen(filename, "rb");
|
||||
size = 0;
|
||||
buf = 0;
|
||||
|
||||
if (!fp) {
|
||||
goto fail;
|
||||
}
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
k = ftell(fp);
|
||||
if (k < 0) goto fail;
|
||||
size = (size_t)k;
|
||||
*size_out = size;
|
||||
if (max_size > 0 && size > max_size) {
|
||||
goto fail;
|
||||
}
|
||||
rewind(fp);
|
||||
buf = (char *)malloc(size ? size : 1);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
pos = 0;
|
||||
while ((n = fread(buf + pos, 1, size - pos, fp))) {
|
||||
pos += n;
|
||||
}
|
||||
if (pos != size) {
|
||||
goto fail;
|
||||
}
|
||||
fclose(fp);
|
||||
*size_out = size;
|
||||
return buf;
|
||||
|
||||
fail:
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
if (buf) {
|
||||
free(buf);
|
||||
}
|
||||
*size_out = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* READFILE_H */
|
||||
Reference in New Issue
Block a user