api

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 15 Imported by: 0

README

Perf of buildPutCall()

Follow perf depending on refactoring commits:

  1. f8b5a7 ✅ Bench buildCallPut()
  2. d140be ♻️ Remove global vars used as temporary buffers
  3. a77786 ⚡️ Remove an unnecessary memory allocation
  4. cb561e ⚡️ Reuse []byte buffer to reduce memory allocation

These commits aims to remove ome global variables while keeping the same performance.

Benchmark

go test -benchmem -bench . ./pkg/rainbow/api
goos: linux
goarch: amd64
pkg: github.com/teal-finance/rainbow/pkg/rainbow/api
cpu: Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz
BenchmarkAlign_buildCallPut/Psy-8      241720     5329 ns/op    2304 B/op    12 allocs/op
BenchmarkAlign_buildCallPut/Deribit-8    1190  1015805 ns/op  510228 B/op  3118 allocs/op
PASS
ok      github.com/teal-finance/rainbow/pkg/rainbow/api 2.668s

Table of results

Metrics from BenchmarkAlign_buildCallPut/Deribit-8:

# ns/op B/op allocs/op
1. 1 083 000 510 000 3118
2. 1 280 000 544 650 5230
3. 1 300 000 537 347 4770
4. 1 170 000 510 200 3118

Conclusion

The refactoring does not increase the number of memory allocations (3118 allocs/op), but the final performance is not as good as the orignal code based on global variables ([]byte buffers).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InteractiveGQLHandler

func InteractiveGQLHandler(endpoint string) http.Handler

Types

type Align added in v0.5.3

type Align struct {
	// contains filtered or unexported fields
}

func NewAlign added in v0.5.3

func NewAlign() Align

func (*Align) BestLimitHTML added in v0.5.3

func (a *Align) BestLimitHTML(option *rainbow.Option) (bidPx, bidSz, askPx, askSz string)

BestLimitHTML is used by the web/API server to align numbers with HTML <tags>.

func (*Align) BestLimitStr added in v0.5.3

func (a *Align) BestLimitStr(option *rainbow.Option) (bidPx, bidSz, askPx, askSz string)

BestLimitStr is used by the CLI to align numbers with whitespaces.

type Handler

type Handler struct {
	Service *rainbow.Service
	// contains filtered or unexported fields
}

func NewHandler added in v0.5.3

func NewHandler(s *rainbow.Service) Handler

func (Handler) CallPut

func (h Handler) CallPut(w http.ResponseWriter, r *http.Request)

func (Handler) GraphQLHandler

func (h Handler) GraphQLHandler() http.Handler

func (Handler) Options

func (h Handler) Options(w http.ResponseWriter, r *http.Request)

type Limit

type Limit struct {
	Bid StrOrder `json:"bid"`
	Ask StrOrder `json:"ask"`
}

type Row

type Row struct {
	Put      Limit   `json:"put"`
	Call     Limit   `json:"call"`
	Date     string  `json:"date"`
	Expiry   string  `json:"expiry"`
	Provider string  `json:"provider"`
	Asset    string  `json:"asset"`
	Strike   float64 `json:"strike"`
}

type StrOrder

type StrOrder struct {
	// Price is often abbreviate "px" used by many Centralized Exchanges
	// such as in the FIX protocol: https://fiximate.fixtrading.org/legacy/en/FIX.5.0SP2/abbreviations.html
	Price string `json:"px"`
	// Size is a shorter synonym for "Quantity".
	Size string `json:"size"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL