Mercurial > demo / examples/db/cl-simple-example.lisp
changeset 36: |
0f678bfd8699 |
parent: |
f54f7cc7458b
|
child: |
c6d0a37a046a |
author: |
ellis <ellis@rwest.io> |
date: |
Tue, 19 Dec 2023 16:52:10 -0500 |
permissions: |
-rw-r--r-- |
description: |
added sample output of cl-simple-example vs c_simple_example |
1 ;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c 3 ;; ref: https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c 7 ;; To compile and run from the shell: 9 sbcl --eval '(ql:quickload :rdb)' \ 10 --eval '(ql:quickload :cli)' \ 11 --eval '(compile-file "cl-simple-example.lisp")' \ 12 --eval '(load "cl-simple-example.fasl")' \ 13 --eval "(sb-ext:save-lisp-and-die \"cl-simple-example\" :toplevel #'cl-simple-example::main :executable t)" 15 time ./cl-simple-example 25 gcc -lrocksdb c_simple_example.c -oc_simple_example 27 time ./c_simple_example 35 (defpackage :examples/rdb/cl-simple-example 36 (:nicknames :cl-simple-example) 37 (:use :cl :std :cli :rdb :sb-alien :rocksdb) 40 (rocksdb:load-rocksdb :save t) 42 (in-package :cl-simple-example) 46 (defvar *num-cpus* (alien-funcall (extern-alien "sysconf" (function long integer)) sb-unix:sc-nprocessors-onln) 49 (defparameter *db-path* "/tmp/rocksdb-cl-simple-example") 51 (defparameter *db-backup-path* "/tmp/rocksdb-cl-simple-example-backup") 54 ;; open Backup Engine that we will use for backing up our database 58 (rocksdb-options-increase-parallelism opt *num-cpus*) ;; set # of online cores 59 (rocksdb-options-optimize-level-style-compaction opt 0) 60 (rocksdb-options-set-create-if-missing opt 1))))) 61 (with-open-backup-engine-raw (be *db-backup-path* options) 63 (with-open-db-raw (db *db-path* options) 65 (put-kv-str-raw db "key" "value") 67 (string= (get-kv-str-raw db "key") "value") 68 ;; create new backup in a directory specified by *db-backup-path* 69 (create-new-backup-raw be db)) 70 ;; if something is wrong, you might want to restore data from last backup 71 (restore-from-latest-backup-raw be *db-path* *db-backup-path*))))