Instantly share code, notes, and snippets.

# Jeff Preshing preshing

Created October 25, 2012 11:28
Sort one million 8-digit numbers in 1MB RAM
View sort1mb.cpp
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 #include #include typedef unsigned int u32; typedef unsigned long long u64; //------------------------------------------------------------------------- // WorkArea //-------------------------------------------------------------------------
Created November 5, 2012 02:52
Sort one million 8-digit numbers in 1MB RAM, with statistics
View sort1mb.cpp
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 #include #include typedef unsigned int u32; typedef unsigned long long u64; //------------------------------------------------------------------------- // WorkArea //-------------------------------------------------------------------------
Created November 5, 2012 02:54
Python script to help validate 1MB Sorter
View validate.py
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
 from subprocess import * import time def validate(sequence): start = time.clock() sorter = Popen('sort1mb.exe', stdin=PIPE, stdout=PIPE, stderr=PIPE) for value in sequence: sorter.stdin.write('%08d\n' % value) sorter.stdin.close() result = [int(line) for line in sorter.stdout]
Created December 24, 2012 04:07
A C++ source file to test the RandomSequenceOfUnique random number generator using TestU01's SmallCrush test suite.
View rsu.cpp
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 "randomsequence.h" #include #include extern "C" { #include "unif01.h" #include "bbattery.h" #include "util.h" }
Last active January 21, 2016 04:44
List the contents of folders recursively, sorted by modification time.
View list_modifications.py
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
 #! /usr/bin/env python # License: http://creativecommons.org/publicdomain/zero/1.0/ # See http://preshing.com/20130115/view-your-filesystem-history-using-python import optparse import os import fnmatch import time # Parse options parser = optparse.OptionParser(usage='Usage: %prog [options] path [path2 ...]')
Created September 22, 2013 19:43
The example from http://preshing.com/20130922/acquire-and-release-fences, rewritten using Mintomic.
View gist:6663087
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 #include struct Message { clock_t tick; const char* str; void* param; };
Created October 27, 2013 15:04
MathJax tags for Octopress
View math.rb
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
 #-------------------------------------------------------------- # MathJax tags for Octopress # # Put this in the plugins folder. # Use a single "inlinemath" tag for inline math. # Use a pair of "math/endmath" tags for math as a standalone paragraph. # The "math" tag takes an optional size argument. # You also need to include MathJax in the page header, for example by adding # # to source/_includes/custom/head.html
Created October 23, 2014 00:13
Generate benchmarks for three implementations of a wait-free queue using C++11 atomics
View capped_spsc_queue.cpp
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
 // // Generate benchmarks for the three queue implementations shown in // Jeff Preshing's CppCon 2014 talk, "How Ubisoft Montreal Develops Games for // Multicore - Before and After C++11". // // Slides: https://github.com/CppCon/CppCon2014/blob/master/Presentations/How%20Ubisoft%20Montreal%20Develops%20Games%20for%20Multicore/How%20Ubisoft%20Montreal%20Develops%20Games%20for%20Multicore%20-%20Before%20and%20After%20C++11%20-%20Jeff%20Preshing%20-%20CppCon%202014.pdf?raw=true // #include #include
Last active February 15, 2023 14:03
A shell script to download packages for, configure, build and install a GCC cross-compiler.
View build_cross_gcc
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
 #! /bin/bash set -e trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG trap 'echo FAILED COMMAND: \$previous_command' EXIT #------------------------------------------------------------------------------------------- # This script will download packages for, configure, build and install a GCC cross-compiler. # Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running. # If you get an error and need to resume the script from some point in the middle, # just delete/comment the preceding lines before running it again.
Created June 13, 2017 02:02
View spinlock-example.cpp
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 class SpinLock { std::atomic m_flag = 0; public: void lock() { int expected = 0; while (!m_flag.compare_exchange_weak(expected, 1, std::memory_order_acquire)) { expected = 0;