Skip to content

Instantly share code, notes, and snippets.

View Raimo33's full-sized avatar
๐ŸŒŽ

Raimo Raimo33

๐ŸŒŽ
View GitHub Profile
#!/usr/bin/env bash
set -e
N=${1:-1}
FILTER=${2:-}
TIME=${3:-}
CURRENT_COMMIT=$(git rev-parse HEAD)
COMMITS=$(git rev-list --max-count="$N" --reverse HEAD)
@Raimo33
Raimo33 / test_commits.sh
Last active October 24, 2025 13:44
Test the previous N commits sequentially (Bitcoincore)
#!/usr/bin/env bash
set -e
N=${1:-1}
CURRENT_COMMIT=$(git rev-parse HEAD)
COMMITS=$(git rev-list --max-count="$N" --reverse HEAD)
trap 'git checkout -q "$CURRENT_COMMIT"' EXIT SIGINT SIGTERM
@Raimo33
Raimo33 / Dockerfile
Last active September 18, 2025 15:14
Bitcoin IBD run
FROM debian:trixie-slim AS builder
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
cmake \
ninja-build \
libboost-system-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
@Raimo33
Raimo33 / find_throwing_benchmarks.sh
Last active October 18, 2025 15:32
Find Throwing Bitcoin Core Benchmarks
#!/usr/bin/env bash
set -u
out_file="benchmarks_throwing_exception.txt"
log="$(mktemp)"
mapfile -t benches < <(./build/bin/bench_bitcoin --list)
rm -f "$out_file"
template <typename T, typename Comparator>
HOT ssize_t forward_lower_bound(std::span<const T> data, const T elem, const Comparator &comp) noexcept
{
static_assert(std::is_integral<T>::value, "T must be an integral type");
static_assert(std::hardware_constructive_interference_size == 64, "Cache line size must be 64 bytes");
static constexpr uint8_t chunk_size = sizeof(__m512i) / sizeof(T);
const T *begin = data.data();
const size_t size = data.size();
size_t remaining = size;
@Raimo33
Raimo33 / sort.c
Created April 4, 2025 17:32
branchless list sort
/*
description:
takes pointers to the head and tail of the singly-linked list.
sorts the list in ascending order by ASCII value.
implementation:
use of mergesort because linked lists inherently don't provide random access. could be bypassed by constructing an array of pointers but that's a poor design choice O(n)...
merge sort is the fastest known sorting algo for linked lists, even though finding the midpoint is O(n/2) = O(n).
use of the slow-fast pointer technique to find the midpoint of the list. same performance as the doubly-linked list -> <- approach.
implemented by changing pointers, even though a char is 1 byte and easier to copy, for better mantainability, reusability, and standard compliance.
@Raimo33
Raimo33 / strtolower.c
Last active March 3, 2025 19:48
SIMD strtolower
//TODO find a way to make them const, forcing prevention of thread safety issues, constexpr??
#ifdef __AVX512F__
static __m512i _512_vec_A_minus_1;
static __m512i _512_vec_case_range;
static __m512i _512_add_mask;
#endif
#ifdef __AVX2__
static __m256i _256_vec_A_minus_1;
static __m256i _256_vec_case_range;
@Raimo33
Raimo33 / speed_optimizations.md
Last active July 24, 2025 14:20
C Speed Optimizations

C Speed Optimization Checklist

This is a list of general-purpose optimizations for C programs, from the most impactful to the tiniest low-level micro-optimizations to squeeze out every last bit of performance. It is meant to be read top-down as a checklist, with each item being a potential optimization to consider. Everything is in order of speed gain.

Algorithm && Data Structures

Choose the best algorithm and data structure for the problem at hand by evaluating:

  1. time complexity
@Raimo33
Raimo33 / pre-commit
Last active March 22, 2025 10:23
Header pre-commit
#!/usr/bin/env python3
import os
import subprocess
import datetime
import re
CREATOR_NAME = "Claudio Raimondi"
CREATOR_EMAIL = "[email protected]"
HEADER_WIDTH = 80
@Raimo33
Raimo33 / Makefile
Last active December 22, 2024 23:16
Docker Compose Makefile
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: craimond <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/06 01:09:08 by craimond #+# #+# #
# Updated: 2024/09/15 14:24:42 by craimond ### ########.fr #
# #