Пример #1
0
package pqueue

import (
	"github.com/fmstephe/matching_engine/msg"
	"math/rand"
	"testing"
)

// A function signature allowing us to switch easily between min and max queues
type popperFun func(*testing.T, *rbtree, *rbtree, *pqueue) (*OrderNode, *OrderNode, *OrderNode)

var msgMkr = msg.NewMessageMaker(1)

func TestPush(t *testing.T) {
	// buys
	testPushAscDesc(t, 100, msg.BUY)
	// buys
	testPushSimple(t, 1, 1, 1, msg.BUY)
	testPushSimple(t, 4, 1, 1, msg.SELL)
	testPushSimple(t, 100, 10, 20, msg.BUY)
	testPushSimple(t, 100, 100, 10000, msg.SELL)
	testPushSimple(t, 1000, 100, 10000, msg.BUY)
}

func TestPushPopSimpleMin(t *testing.T) {
	// buys
	testPushPopSimple(t, 1, 1, 1, msg.BUY, maxPopper)
	testPushPopSimple(t, 4, 1, 1, msg.BUY, maxPopper)
	testPushPopSimple(t, 100, 10, 20, msg.BUY, maxPopper)
	testPushPopSimple(t, 100, 100, 10000, msg.BUY, maxPopper)
	testPushPopSimple(t, 1000, 100, 10000, msg.BUY, maxPopper)
Пример #2
0
package matcher

import (
	"github.com/fmstephe/matching_engine/msg"
	"runtime"
	"testing"
)

const (
	stockId = 1
	trader1 = 1
	trader2 = 2
	trader3 = 3
)

var matchMaker = msg.NewMessageMaker(100)

type responseVals struct {
	price   uint64
	amount  uint32
	tradeId uint32
	stockId uint32
}

func TestPrice(t *testing.T) {
	testPrice(t, 1, 1, 1)
	testPrice(t, 2, 1, 1)
	testPrice(t, 3, 1, 2)
	testPrice(t, 4, 1, 2)
	testPrice(t, 5, 1, 3)
	testPrice(t, 6, 1, 3)
Пример #3
0
package matcher

import (
	"github.com/fmstephe/matching_engine/msg"
	"testing"
)

var cmprMaker = msg.NewMessageMaker(1)

func TestCompareMatchers(t *testing.T) {
	compareMatchers(t, 100, 1, 1, 1)
	compareMatchers(t, 100, 10, 1, 1)
	compareMatchers(t, 100, 100, 1, 1)
	//
	compareMatchers(t, 100, 1, 1, 2)
	compareMatchers(t, 100, 10, 1, 2)
	compareMatchers(t, 100, 100, 1, 2)
	//
	compareMatchers(t, 100, 1, 10, 20)
	compareMatchers(t, 100, 10, 10, 20)
	compareMatchers(t, 100, 100, 10, 20)
	//
	compareMatchers(t, 100, 1, 100, 2000)
	compareMatchers(t, 100, 10, 100, 2000)
	compareMatchers(t, 100, 100, 100, 2000)
}

func compareMatchers(t *testing.T, orderPairs, depth int, lowPrice, highPrice uint64) {
	refIn := make(chan *msg.Message)
	refOut := make(chan *msg.Message, orderPairs*2)
	refm := newRefmatcher(lowPrice, highPrice)
Пример #4
0
	"os"
	"runtime/pprof"
	"time"
)

const (
	StockId = uint32(1)
)

var (
	filePath   = flag.String("f", "", "Relative path to an ITCH file providing test data")
	profile    = flag.String("p", "", "Write out a profile of this application, 'cpu' and 'mem' supported")
	orderNum   = flag.Int("o", 100, "The number of orders to generate. Ignored if -f is provided")
	delDelay   = flag.Int("d", 10, "The number of orders generated before we begin deleting existing orders")
	perfRand   = rand.New(rand.NewSource(1))
	orderMaker = msg.NewMessageMaker(1)
)

func main() {
	doPerf(true)
}

func doPerf(log bool) {
	flag.Parse()
	orderData := getData()
	orderCount := fstrconv.Itoa64Comma(int64(len(orderData)))
	if log {
		println(orderCount, "OrderNodes Built")
	}
	in := make(chan *msg.Message, len(orderData))
	out := make(chan *msg.Message, len(orderData))