Browse Source

switch from branchless to branched approach

master
Jonathan Strong 4 years ago
parent
commit
2124012010
1 changed files with 17 additions and 5 deletions
  1. +17
    -5
      src/binary-serialization.rs

+ 17
- 5
src/binary-serialization.rs View File

@@ -100,22 +100,33 @@ fn easy_query<W>(
let mut gdax_amount = 0.0; let mut gdax_amount = 0.0;
let mut n_gdax = 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 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 ]); 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 macro_rules! update { // in macro to avoid repeating code once outside loop, and again in loop body
($trade:ident) => {{ ($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_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 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_total += is_bmex_btc_usd * total;
bmex_amount += is_bmex_btc_usd * amount; bmex_amount += is_bmex_btc_usd * amount;
n_bmex += is_bmex_btc_usd as usize * 1; n_bmex += is_bmex_btc_usd as usize * 1;
@@ -123,6 +134,7 @@ fn easy_query<W>(
gdax_total += is_gdax_btc_usd * total; gdax_total += is_gdax_btc_usd * total;
gdax_amount += is_gdax_btc_usd * amount; gdax_amount += is_gdax_btc_usd * amount;
n_gdax += is_gdax_btc_usd as usize * 1; n_gdax += is_gdax_btc_usd as usize * 1;
*/




//match ($trade.exch(), $trade.base(), $trade.quote()) { //match ($trade.exch(), $trade.base(), $trade.quote()) {


Loading…
Cancel
Save