mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
49 lines
2.5 KiB
C
49 lines
2.5 KiB
C
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
│ Copyright 2024 Justine Alexandra Roberts Tunney │
|
|
│ │
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
|
│ │
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
#include "libc/assert.h"
|
|
#include "libc/stdio/rand.h"
|
|
#include "libc/testlib/benchmark.h"
|
|
#include "libc/testlib/testlib.h"
|
|
|
|
uint64_t getrandom64(void) {
|
|
uint64_t x;
|
|
unassert(getrandom(&x, 8, 0) == 8);
|
|
return x;
|
|
}
|
|
|
|
uint64_t getentropy64(void) {
|
|
uint64_t x;
|
|
unassert(!getentropy(&x, 8));
|
|
return x;
|
|
}
|
|
|
|
TEST(lemur64, test) {
|
|
EXPECT_EQ(1819718037028923529, lemur64());
|
|
EXPECT_EQ(-3120132252617434764, lemur64());
|
|
}
|
|
|
|
BENCH(lemur64, bench) {
|
|
BENCHMARK(10000, 8, X(lemur64()));
|
|
BENCHMARK(10000, 4, X(rand()));
|
|
BENCHMARK(10000, 8, X(_rand64()));
|
|
BENCHMARK(10000, 8, X(rdrand()));
|
|
BENCHMARK(10000, 8, X(rdseed()));
|
|
BENCHMARK(10000, 8, X(getrandom64()));
|
|
BENCHMARK(10000, 8, X(getentropy64()));
|
|
}
|