Improve redbean

- Improve serialization
- Add Benchmark() API to redbean
- Refactor UNIX API to be assert() friendly
- Make the redbean Lua REPL print data structures
- Fix recent regressions in linenoise reverse search
- Add -i flag so redbean can be a language interpreter
This commit is contained in:
Justine Tunney 2022-04-25 08:30:14 -07:00
parent 2046c0d2ae
commit 451e3f73d9
74 changed files with 1781 additions and 1024 deletions

View file

@ -17,6 +17,8 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/metastat.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
@ -24,6 +26,7 @@
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/nr.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -68,18 +71,34 @@ static long Stat(const char *path, struct stat *st) {
return ax;
}
static long Fstatat(const char *path, struct stat *st) {
long ax, di, si, dx;
register long r10 asm("r10") = 0;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx), "+r"(r10)
: "0"(__NR_fstatat), "1"(AT_FDCWD), "2"(path), "3"(st)
: "rcx", "r8", "r9", "r11", "memory", "cc");
return ax;
}
BENCH(stat, bench) {
struct stat st;
union metastat ms;
EXPECT_SYS(0, 0, makedirs(".python/test", 0755));
EZBENCH2("__stat2cosmo", donothing, __stat2cosmo(&st, &ms));
EXPECT_SYS(0, 0,
touch(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
0644));
if (!IsWindows()) {
if (!IsWindows() && !IsFreebsd()) {
EZBENCH2("stat syscall", donothing,
Stat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
EZBENCH2("fstatat syscall", donothing,
Fstatat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
}
EZBENCH2("stat() fs", donothing,
stat(".python/test/"

View file

@ -19,8 +19,11 @@
#include "libc/bits/bits.h"
#include "libc/bits/xchg.internal.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/kprintf.h"
#include "libc/linux/mmap.h"
#include "libc/linux/munmap.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/rand/rand.h"
@ -33,6 +36,7 @@
#include "libc/sysv/consts/msync.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
@ -281,3 +285,57 @@ TEST(mmap, sharedFileMapFork) {
EXPECT_NE(-1, close(fd));
EXPECT_NE(-1, unlink(path));
}
////////////////////////////////////////////////////////////////////////////////
// BENCHMARKS
#define N (EZBENCH_COUNT * EZBENCH_TRIES)
int count;
void *ptrs[N];
void BenchUnmap(void) {
int i;
for (i = 0; i < count; ++i) {
if (ptrs[i]) {
ASSERT_EQ(0, munmap(ptrs[i], FRAMESIZE));
}
}
}
void BenchMmapPrivate(void) {
void *p;
p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
-1, 0);
if (p == MAP_FAILED) abort();
ptrs[count++] = p;
}
BENCH(mmap, bench) {
EZBENCH2("mmap", donothing, BenchMmapPrivate());
BenchUnmap();
}
void BenchUnmapLinux(void) {
int i;
for (i = 0; i < count; ++i) {
if (ptrs[i]) {
ASSERT_EQ(0, LinuxMunmap(ptrs[i], FRAMESIZE));
}
}
}
void BenchMmapPrivateLinux(void) {
void *p;
p = (void *)LinuxMmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) abort();
ptrs[count++] = p;
}
BENCH(mmap, benchLinux) {
void *p;
if (!IsLinux()) return;
EZBENCH2("mmap (linux)", donothing, BenchMmapPrivateLinux());
BenchUnmapLinux();
}