Skip to content

Instantly share code, notes, and snippets.

@mikeb01
mikeb01 / gist:1510494
Created December 22, 2011 14:34
Order Protocol Event
<order>
<timeInForce>ImmediateOrCancel</timeInForce>
<instructionId>1733844027851145216</instructionId>
<originalInstructionId>1733844027851145216</originalInstructionId>
<orderId>AAK8oAAAAAAAAAAF</orderId>
<accountId>1393236922</accountId>
<instrumentId>179361</instrumentId>
<quantity>30</quantity>
<matchedQuantity>30</matchedQuantity>
<matchedCost>22.1</matchedCost>
@mikeb01
mikeb01 / ExecutionTracking.java
Created December 22, 2011 15:33
Tracked Execution for an Order
public class ExecutionTracking implements OrderEventListener, ExecutionEventListener
{
private final Session tradingSession;
final Map<Long, Order> lastOrderStateByInstructionId = new HashMap<Long, Order>();
Order currentOrder = null;
long currentFilledQuantity;
long currentCancelledQuantity;
public ExecutionTracking(final Session tradingSession)
{
public long incrementAndGet(AtomicLong atomic) {
long expected;
long updated
do {
expected = atomic.get();
updated = expected + 1;
}
while (!atomic.compareAndSet(expected, updated));
return updated;
public void serialisePublishing(final long sequence,
final Sequence cursor,
final int batchSize) {
final long expectedSequence = sequence - batchSize;
while (expectedSequence != cursor.get()) {
// busy spin
}
cursor.set(sequence);
public void serialisePublishing(final long sequence,
final Sequence cursor,
final int batchSize) {
// Guard condition, limit the number of pending publications
int counter = RETRIES;
while (sequence - cursor.get() > pendingPublication.length()) {
if (--counter == 0) {
Thread.yield();
counter = RETRIES;
#include <stdio.h>
static void cpuid(int op1, int op2, int *data) {
asm("cpuid"
: "=a" (data[0]), "=b" (data[1]), "=c" (data[3]), "=d" (data[2])
: "a"(op1), "c"(op2));
}
int main(int argc, char** argv) {
int values[5];
#include <stdio.h>
static void cpuid(int op1, int op2, int *data) {
asm("cpuid"
: "=a" (data[0]), "=b" (data[1]), "=c" (data[2]), "=d" (data[3])
: "a"(op1), "c"(op2));
}
int main (int argc, const char * argv[]) {
int values[4];
extern "C" {
/* from sys/osfmk/i386/mp.c */
extern void mp_rendezvous(void (*setup_func)(void *),
void (*action_func)(void *),
void (*teardown_func)(void *),
void *arg);
extern int cpu_number(void);
}
package com.lmax.disruptor;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
@mikeb01
mikeb01 / PopCntTest.java
Created August 30, 2012 09:18
POPCNT Demo
public class PopCntTest
{
public static void main(String[] args)
{
int result = 0;
for (int i = 0; i < 1000000000; i++)
{
result += Integer.bitCount(i);
}