Skip to content

Instantly share code, notes, and snippets.

View chrisvest's full-sized avatar
🍉

Chris Vest chrisvest

🍉
View GitHub Profile
@chrisvest
chrisvest / Rolls.scala
Last active December 15, 2015 08:29
Savage Worlds die rolls, with wildcard dies and aces.
package test
import java.util.Random
/**
* What are the chances I get with the different dice in Savage Worlds?
*
* Of course, I could have just calculated the chances directly, using maths,
* but what's the fun in that? Besides, it's Sunday... give me a break.
*/
object Rolls {

Welcome, Adventurer!

You are at the intersect of JPA 1.0, HSQLDB and streaming Blobs.

You carry a single piece of paper. It is documentation, but it won't help you do what you want.

There are no doors and no windows. It is dark and you cannot tell if you are outside or inside. In fact, the concept has ceased to make sense.

There is no air and no gravity. You float helplessly in a featureless, endless black void, accompanied only by the memory of countless unhelpful forum posts and useless google search results.

@chrisvest
chrisvest / gist:4625486
Last active December 11, 2015 16:08
The message-passing benchmark for object-pools.

The Message-Passing Benchmark

This is the message-passing benchmark for object-pools. Two threads cooperate such that one thread is claiming objects from the pool, transfer them to the other thread through a special optimised queue, and the other thread releases the objects back into the pool.

This scheme defeats optimisations that are based on caching objects in ThreadLocals, and BlazePool, which is otherwise very fast, clearly suffers

@chrisvest
chrisvest / gist:4593389
Last active December 11, 2015 11:28
These tests were run on a Core2 Duo, 2010 MacBook Air. There's still some ways to go for BlazePool, I think...

Performance of various queues, and BlazePool

0 - ops/sec=11,510,995 - OneToOneConcurrentArrayQueue result=777
1 - ops/sec=10,772,583 - OneToOneConcurrentArrayQueue result=777
2 - ops/sec=11,335,999 - OneToOneConcurrentArrayQueue result=777
3 - ops/sec=11,223,871 - OneToOneConcurrentArrayQueue result=777
4 - ops/sec=11,307,302 - OneToOneConcurrentArrayQueue result=777

0 - ops/sec=29,601,790 - OneToOneConcurrentArrayQueue2 result=777

@chrisvest
chrisvest / TestOfFaith.java
Created January 15, 2013 22:01
Java, uhm, "for-comprehensions"
import java.util.ArrayList;
import java.util.List;
public class TestOfFaith {
@SuppressWarnings("serial")
public static void main(String[] args) {
final int[] xs = new int[] {1, 2, 3, 4, 5, 6};
List<Integer> stuff = new ArrayList<Integer>() {{ for (int a : xs) for (int b : xs) if (a * b % 2 == 1) {
add(a * b);
@chrisvest
chrisvest / CheapReadWriteLockPattern.java
Created January 4, 2013 06:43
The Cheap Read-Write Lock pattern allow many readers to proceed concurrently, while writers serialise. The cool thing about this particular way to doing a Read-Write lock, is that readers never block writers.
/**
* The Cheap Read-Write Lock pattern allow many readers to proceed
* concurrently, while writers serialise. The cool thing about this
* particular way to doing a Read-Write lock, is that readers never
* block writers.
*/
public class CheapReadWriteLockPattern {
// SINGLE-FIELD:
@chrisvest
chrisvest / ConwayTest.scala
Created December 8, 2012 19:14
Conways Game of Life #gdcr12
package test
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
class ConwayTest extends FunSuite with BeforeAndAfter with ShouldMatchers {
///// IMPLEMENTATION:
type Cell = (Int,Int)
def conway(world: Set[Cell]): Stream[Set[Cell]] = {
@chrisvest
chrisvest / ArrayStackBug.scala
Created December 1, 2012 21:47
mapping the ArrayStack turns some results into nulls
package test
import scala.collection.mutable.ArrayStack
object ArrayStackBug {
sealed abstract class Group
case object Alpha extends Group
case object Numb extends Group
case class Thing(
import scala.collection.immutable.Stream._
object Main {
class Puff(huff: String)
class Pony(effect: Puff => Unit)
class Factory(ponies: Stream[Pony]) extends (Puff => Unit) {
def apply(puff: Puff): Unit = ponies.foreach(_.effect(puff))
}
def main(args: Array[String]): Unit = {
@chrisvest
chrisvest / data
Created June 23, 2012 21:19
Benchmark results data, raw: Stormpot 2.0 vs. Commons-Pool 1.6
;; GenericObjectPool and StackObjectPool are both Commons-Pool implementations.
;; QueuePool is the Stormpot implementation.
;; Each implementation get 10 runs in random order, after thorough JIT warmup, at various thread-contention levels.
;; The abbreviation "lat" means latency in the numbers bellow. The Latency is in milliseconds.
;; A "trial" is an object being removed from a pool, and then returned.
;; The pools are all configured to contain 10 objects, and therefore only the last benchmark with 16 threads risk depleting the pools.
;; The pools are told to expire their objects after half a minute, however, we only trial them for half a second.
alucard:stormpot-benchmark cvh (master)$
alucard:stormpot-benchmark cvh (master)$