Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
camel-cdr committed Feb 1, 2025
1 parent c0a8d70 commit a673553
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 9 additions & 4 deletions cauldron/bench.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* arg.h -- A POSIX compliant argument parser based on plan9's arg(3)
/* bench.h -- A minimal benchmarking library
* Olaf Bernstein <[email protected]>
* Distributed under the MIT license, see license at the end of the file.
* New versions available at https://github.com/camel-cdr/cauldron
Expand Down Expand Up @@ -57,17 +57,17 @@ typedef struct {
BenchRecord *records;
/* temporaries */
size_t i;
double ns;
double secs;
} Bench;

static Bench benchInternal;

#define BENCH(title, warmup, samples) \
for (bench_append(title), \
benchInternal.i = (warmup) + (samples); \
(benchInternal.ns = bench_gettime()), benchInternal.i--; \
(benchInternal.secs = bench_gettime()), benchInternal.i--; \
benchInternal.i < (samples) ? \
bench_update(bench_gettime()-benchInternal.ns),0 : 0)
bench_update(bench_gettime()-benchInternal.secs),0 : 0)

static inline double
bench_gettime(void)
Expand Down Expand Up @@ -143,8 +143,13 @@ bench_done(void)
putchar(' ');

printf("mean: %.9e, stddev: %.2e, min: %.9e \n",
#ifdef BENCH_DONT_NORMALIZE
b->records[i].mean,
sqrt(b->records[i].M2 / b->records[i].count),
#else
b->records[i].mean / minmean,
sqrt(b->records[i].M2 / b->records[i].count) / minmean,
#endif
b->records[i].min);
}
b->count = 0;
Expand Down
10 changes: 9 additions & 1 deletion cauldron/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* 6. Shuffling
* References
* Licensing
* Alternative A - MIT License
* MIT License
*
* 1. Introduction =============================================================
*
Expand Down Expand Up @@ -68,6 +68,7 @@
# endif
#endif

#include <limits.h>
#include <float.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -1453,6 +1454,13 @@ dist_uniform(uint64_t x)
}

/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* WARNING: this code does currently not work correctly for subnormals.
* The probability of subnormals isn't quite correct, and there needs to be
* a new special case for subnormals when both a and b are subnormals.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
*
* Another solution is to generate every representable floating-point number
* with a probability proportional to the covered real number range. <15>
* So obtaining a number in a floating-point subrange [s1,s2] of the output
Expand Down
4 changes: 2 additions & 2 deletions cauldron/stretchy-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ sb__realloc(void *ptr, size_t num_bytes)
/* can be zero initialized */
#define Sb(T) struct { T *at; size_t _len, _cap; }

#define sb_len(a) ((size_t const)(a)._len)
#define sb_cap(a) ((size_t const)(a)._cap)
#define sb_len(a) (+(a)._len)
#define sb_cap(a) (+(a)._cap)

#define sb_begin(a) ((a).at)
#define sb_last(a) ((a).at + (a)._len - 1)
Expand Down

0 comments on commit a673553

Please sign in to comment.