From 21240120106358a5e74dc8e472a31cd6af079c1a Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Wed, 22 Apr 2020 18:14:07 -0400 Subject: [PATCH] switch from branchless to branched approach --- src/binary-serialization.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/binary-serialization.rs b/src/binary-serialization.rs index b1b8100..3e21658 100644 --- a/src/binary-serialization.rs +++ b/src/binary-serialization.rs @@ -100,22 +100,33 @@ fn easy_query( let mut gdax_amount = 0.0; let mut n_gdax = 0; - const MASK : i32 = i32::from_le_bytes([ 255, 255, 255, 0]); + const MASK : i32 = i32::from_le_bytes([ 255, 255, 255, 0 ]); const BMEX_BTC_USD : i32 = i32::from_le_bytes([ e!(bmex) as u8, c!(btc) as u8, c!(usd) as u8, 0 ]); const GDAX_BTC_USD : i32 = i32::from_le_bytes([ e!(gdax) as u8, c!(btc) as u8, c!(usd) as u8, 0 ]); macro_rules! update { // in macro to avoid repeating code once outside loop, and again in loop body ($trade:ident) => {{ - let meta_sans_side: i32 = $trade.meta_i32() & MASK; + let meta_sans_side: i32 = $trade.meta_i32() & MASK; + let amount = $trade.amount(); + let total = $trade.price() * amount; + + if meta_sans_side == BMEX_BTC_USD { + bmex_total += total; + bmex_amount += amount; + n_bmex += 1; + } else if meta_sans_side == GDAX_BTC_USD { + gdax_total += total; + gdax_amount += amount; + n_gdax += 1; + } + + /* let is_bmex_btc_usd: f64 = (meta_sans_side == BMEX_BTC_USD) as u8 as f64; let is_gdax_btc_usd: f64 = (meta_sans_side == GDAX_BTC_USD) as u8 as f64; - let amount = $trade.amount(); - let total = $trade.price() * amount; - bmex_total += is_bmex_btc_usd * total; bmex_amount += is_bmex_btc_usd * amount; n_bmex += is_bmex_btc_usd as usize * 1; @@ -123,6 +134,7 @@ fn easy_query( gdax_total += is_gdax_btc_usd * total; gdax_amount += is_gdax_btc_usd * amount; n_gdax += is_gdax_btc_usd as usize * 1; + */ //match ($trade.exch(), $trade.base(), $trade.quote()) {