- APPEND
- DECR
- DECRBY
- GET
- GETRANGE
- GETSET
- INCR
- INCRBY
- INCRBYFLOAT
- MGET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Benchmark = require('benchmark'); | |
function getRandomInt(max) { | |
return Math.floor(Math.random() * max); | |
} | |
var set = new Set(); | |
var array = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
long long l = -2; | |
printf("%lld\n", l); | |
printf("%llu\n", (unsigned long long) l); | |
printf("%llu\n", (uint64_t) l); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sequenceDiagram | |
participant Frontend | |
participant Backend | |
Frontend->>+Frontend: Persist intent record | |
Frontend->>+Backend: Create resource request | |
Backend-->>-Frontend: Newly created resource | |
Note right of Backend: Resource must include a unique identifier | |
Frontend->>+Frontend: Update intent record with the unique identifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
use std::{io,mem,ptr,time}; | |
use std::os::unix::io::RawFd; | |
use std::net::TcpStream; | |
use std::os::unix::io::AsRawFd; | |
// use std::io::Read; | |
pub struct FdSet(libc::fd_set); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <inttypes.h> | |
size_t redisPopcount(void *s, long count) { | |
size_t bits = 0; | |
unsigned char *p = s; | |
uint32_t *p4; | |
static const unsigned char bitsinbyte[256] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8}; | |
/* Count initial bytes not aligned to 32 bit. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'forwardable' | |
module BYORedis | |
class SortedArray | |
extend Forwardable | |
def_delegators :@underlying, :[], :delete_if, :size, :each, :delete_at, :shift, | |
:bsearch_index, :map, :each_with_index, :pop | |
def initialize(*fields) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BYORedis | |
class SkipList | |
MAX_LEVEL = 32 # 32 is what Redis uses | |
P = 0.25 | |
Node = Struct.new(:member, :score, :backward, :levels, keyword_init: true) | |
Level = Struct.new(:forward, :span, keyword_init: true) | |
attr_reader :length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BYORedis | |
class IntSet | |
INT16_MIN = -2**15 # -32,768 | |
INT16_MAX = 2**15 - 1 # 32,767 | |
INT32_MIN = -2**31 # -2,147,483,648 | |
INT32_MAX = 2**31 - 1 # 2,147,483,647 | |
INT64_MIN = -2**63 # -9,223,372,036,854,775,808 | |
INT64_MAX = 2**63 - 1 # 9,223,372,036,854,775,807 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
require 'bigdecimal' | |
Benchmark.ips do |x| | |
x.report('BD: % 1') { num = BigDecimal(rand(1_000_000_000)); num % 1 == 0 } | |
x.report('BD: == truncate') { num = BigDecimal(rand(1_000_000_000)); num.truncate == num } | |
x.report('BD: frac == 0') { num = BigDecimal(rand(1_000_000_000)); num.frac == 0 } | |
x.report('Float: % 1') { num = rand(1_000_000_000).to_f; num % 1 == 0 } |