Skip to content

Instantly share code, notes, and snippets.

Let's say you have to perform a 4-way case analysis and are given a choice between cascaded 2-way branches or a single 4-way branch.

What's the difference in branch misprediction penalties, assuming the 4 cases are random?

Denote the branch penalty by x (which is 15-20 cycles on Sky Lake according to Agner Fog).

With the 4-way branch, the worst-case branch penalty is x. The expected branch penalty is 3/4 x: there's a 3/4 chance of x penalty.

import csv
import json
from unidecode import unidecode
anum = set('abcdefghijklmnopqrstuvwxyz0123456789')
sfxs = {}
print("Computing suffices...")
for i, x in enumerate(json.load(open('all_songs.json'))):
def add(a, t, i):
@dsprenkels
dsprenkels / peage-print
Last active May 12, 2017 20:18
script for easy printing to Péage from lilo @ Radboud University
#!/bin/bash
# Author: Daan Sprenkels <dsprenkels@science.ru.nl>
# Description: script for easy printing to Péage from lilo
PROGNAME="peage-print"
VERSION="0.1.2 (2016-08-30)"
PRINT_SERVER="payprint01.ru.nl"
PRINT_QUEUE="RU-Print"
SNUMBER_CACHE_FILE="$HOME/.cache/snumber.txt"
@camilstaps
camilstaps / WritingPseudocode.md
Last active March 31, 2023 02:13
How to write good pseudocode

How to write good Pseudocode

This is an unfinished list of remarks on how to write good pseudocode.

What is pseudocode?

Pseudocode is a loosely defined way of transmitting the concept of an algorithm from a writer to a reader. Central is the efficiency of this communication, not the interpretability of the code by an automated program (e.g., a parser).

@m-ou-se
m-ou-se / replace-debian-with-arch.txt
Last active October 22, 2023 12:16
Instructions to replace a live Debian installation with Arch
# Download latest archlinux bootstrap package, see https://www.archlinux.org/download/
wget 'ftp://ftp.nluug.nl/pub/os/Linux/distr/archlinux/iso/latest/archlinux-bootstrap-*-x86_64.tar.gz'
# Make sure you'll have enough entropy for pacman-key later.
apt-get install haveged
# Install the arch bootstrap image in a tmpfs.
mount -t tmpfs none /mnt
cd /mnt
tar xvf ~/archlinux-bootstrap-*-x86_64.tar.gz --strip-components=1
@aaronhurt
aaronhurt / curltest.c
Last active November 26, 2023 10:29
example code using libcurl and json-c to post and parse a return from http://jsonplaceholder.typicode.com
/**
* example C code using libcurl and json-c
* to post and return a payload using
* http://jsonplaceholder.typicode.com
*
* License:
*
* This code is licensed under MIT license
* https://opensource.org/licenses/MIT
*
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@Ignavia-Snippets
Ignavia-Snippets / timeit.c
Created December 28, 2013 14:31
C: Timeit
#include <time.h>
#include <sys/time.h>
#include "timeit.h"
double timeit(void (*f)()) {
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
(*f)();
@holms
holms / install-metasploit-debian.md
Last active October 10, 2020 14:13
metasploit install in debian wheezy

Debian Wheezy Metasploit Setup

Install depedencies

apt-get install build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev openjdk-7-jre subversion git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev vncviewer libyaml-dev ruby1.9.3 nmap -y
gem install --verbose --debug pcaprub wirble pg sqlite3 msgpack activerecord redcarpet rspec simplecov yard bundler
@klalle
klalle / nRF2401_Transmitter.c
Last active October 12, 2022 11:30
This is a simple code that waits for the USART interrupt, that receives the payload from the USART and then calls the send-function to broadcast the data to listening nRFs.
/*
* RF_Tranceiver.c
*
* Created: 2012-08-10 15:24:35
* Author: Kalle
* Atmega88
*/
#include <avr/io.h>
#include <stdio.h>