Here is the sample JSON file:
"{\"topic\":\"trade.BTCUSDT\",\"data\":[{\"symbol\":\"BTCUSDT\",\"tick_direction\":\"PlusTick\",\"price\":\"19431.00\",\"size\":0.2,\"timestamp\":\"2022-10-18T14:50:20.000Z\",\"trade_time_ms\":\"1666104620275\",\"side\":\"Buy\",\"trade_id\":\"e6be9409-2886-5eb6-bec9-de01e1ec6bf6\",\"is_block_trade\":\"false\"},{\"symbol\":\"BTCUSDT\",\"tick_direction\":\"MinusTick\",\"price\":\"19430.50\",\"size\":1.989,\"timestamp\":\"2022-10-18T14:50:20.000Z\",\"trade_time_ms\":\"1666104620299\",\"side\":\"Sell\",\"trade_id\":\"bb706542-5d3b-5e34-8767-c05ab4df7556\",\"is_block_trade\":\"false\"},{\"symbol\":\"BTCUSDT\",\"tick_direction\":\"ZeroMinusTick\",\"price\":\"19430.50\",\"size\":0.007,\"timestamp\":\"2022-10-18T14:50:20.000Z\",\"trade_time_ms\":\"1666104620314\",\"side\":\"Sell\",\"trade_id\":\"a143da10-3409-5383-b557-b93ceeba4ca8\",\"is_block_trade\":\"false\"},{\"symbol\":\"BTCUSDT\",\"tick_direction\":\"PlusTick\",\"price\":\"19431.00\",\"size\":0.001,\"timestamp\":\"2022-10-18T14:50:20.000Z\",\"trade_time_ms\":\"1666104620327\",\"side\":\"Buy\",\"trade_id\":\"7bae9053-e42b-52bd-92c5-6be8a4283525\",\"is_block_trade\":\"false\"}]}"
I was under the impression if I give it a custom type it would make it faster but I was wrong. Here is the defined structure:
struct Ticket
symbol::String
tick_direction::String
price::String
size::Float64
timestamp::String
trade_time_ms::String
side::String
trade_id::String
is_block_trade::String
end
struct Tape
topic::String
data::Vector{Ticket}
end
StructTypes.StructType(::Type{Tape}) = StructTypes.Struct()
Now with a simple JSON3.read(Sample)
I get:
BenchmarkTools.Trial: 10000 samples with 9 evaluations.
Range (min β¦ max): 2.897 ΞΌs β¦ 1.257 ms β GC (min β¦ max): 0.00% β¦ 99.68%
Time (median): 3.300 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 4.230 ΞΌs Β± 29.736 ΞΌs β GC (mean Β± Ο): 18.36% Β± 2.63%
βββββββββ
βββ βββ β
ββββββββββββββββββ
βββββββ
ββ
βββ
βββββββββββββββ
ββ
βββ
ββββββββ β
2.9 ΞΌs Histogram: log(frequency) by time 6.98 ΞΌs <
Memory estimate: 4.38 KiB, allocs estimate: 7.
With the custom type defined JSON3.read(Sample, Tape)
I get:
BenchmarkTools.Trial: 10000 samples with 5 evaluations.
Range (min β¦ max): 6.813 ΞΌs β¦ 763.641 ΞΌs β GC (min β¦ max): 0.00% β¦ 98.76%
Time (median): 6.977 ΞΌs β GC (median): 0.00%
Time (mean Β± Ο): 7.479 ΞΌs Β± 12.962 ΞΌs β GC (mean Β± Ο): 2.98% Β± 1.71%
ββββ
βββ ββ β
ββββββββββββββββββββββββββ
ββ
βββββ
β
β
βββ
βββ
β
ββββββββββββββββ
β β
6.81 ΞΌs Histogram: log(frequency) by time 13.5 ΞΌs <
Memory estimate: 3.42 KiB, allocs estimate: 48.
Shouldnβt giving hints about the structure of the json file make it more performant? Why Is it regressing?