Categorygithub.com/geseq/udecimal
repositorypackage
0.0.0-20211126195629-659dde5a92d8
Repository: https://github.com/geseq/udecimal.git
Documentation: pkg.go.dev

# README

Summary

Based on https://github.com/robaho/fixed

A fixed place unsigned numeric library designed for performance.

All numbers have a fixed 8 decimal places, and the maximum permitted value is +- 99999999999, or just under 100 billion.

The library is safe for concurrent use. It has built-in support for binary and json marshalling.

It is ideally suited for high performance trading financial systems. All common math operations are completed with 0 allocs.

Design Goals

Primarily developed to test performance charactersitics in an order book.

The decimal.Decimal API uses panics for some error handling, since critical operation errors would be unrecoverable in a deterministic order book.

Performance

BenchmarkAddDecimal-8                   2000000000           0.87 ns/op        0 B/op          0 allocs/op
BenchmarkAddShopspringDecimal-8          5000000           247 ns/op         176 B/op          8 allocs/op
BenchmarkAddBigInt-8                    100000000           16.4 ns/op         0 B/op          0 allocs/op
BenchmarkAddBigFloat-8                  20000000            85.9 ns/op        48 B/op          1 allocs/op
BenchmarkMulDecimal-8                   300000000            4.07 ns/op        0 B/op          0 allocs/op
BenchmarkMulShopspringDecimal-8         20000000            75.4 ns/op        80 B/op          2 allocs/op
BenchmarkMulBigInt-8                    100000000           19.2 ns/op         0 B/op          0 allocs/op
BenchmarkMulBigFloat-8                  50000000            39.3 ns/op         0 B/op          0 allocs/op
BenchmarkDivDecimal-8                   300000000            5.22 ns/op        0 B/op          0 allocs/op
BenchmarkDivShopspringDecimal-8          2000000           792 ns/op         568 B/op         21 allocs/op
BenchmarkDivBigInt-8                    30000000            48.0 ns/op         8 B/op          1 allocs/op
BenchmarkDivBigFloat-8                  20000000           116 ns/op          24 B/op          2 allocs/op
BenchmarkCmpDecimal-8                   2000000000           0.42 ns/op        0 B/op          0 allocs/op
BenchmarkCmpShopspringDecimal-8         200000000            8.55 ns/op        0 B/op          0 allocs/op
BenchmarkCmpBigInt-8                    200000000            6.12 ns/op        0 B/op          0 allocs/op
BenchmarkCmpBigFloat-8                  300000000            5.33 ns/op        0 B/op          0 allocs/op
BenchmarkStringDecimal-8                20000000            61.5 ns/op        32 B/op          1 allocs/op
BenchmarkStringNDecimal-8               20000000            60.7 ns/op        32 B/op          1 allocs/op
BenchmarkStringShopspringDecimal-8       5000000           242 ns/op          64 B/op          5 allocs/op
BenchmarkStringBigInt-8                 10000000           139 ns/op          24 B/op          2 allocs/op
BenchmarkStringBigFloat-8                3000000           449 ns/op         192 B/op          8 allocs/op
BenchmarkWriteTo-8                      50000000            42.9 ns/op        21 B/op          0 allocs/op

The "decimal" above is the common shopspring decimal library