Browse Source

use integer masking to speed up row filtering a lot

master
Jonathan Strong 4 years ago
parent
commit
d802aab598
2 changed files with 49 additions and 21 deletions
  1. +35
    -14
      src/binary-serialization.rs
  2. +14
    -7
      src/encoding.rs

+ 35
- 14
src/binary-serialization.rs View File

@@ -100,24 +100,45 @@ fn easy_query<W>(
let mut gdax_amount = 0.0;
let mut n_gdax = 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) => {{
match ($trade.exch(), $trade.base(), $trade.quote()) {
(Ok(e!(bmex)), Ok(c!(btc)), Ok(c!(usd))) => {
bmex_total += $trade.price() * $trade.amount();
bmex_amount += $trade.amount();
n_bmex += 1;
}

(Ok(e!(gdax)), Ok(c!(btc)), Ok(c!(usd))) => {
gdax_total += $trade.price() * $trade.amount();
gdax_amount += $trade.amount();
n_gdax += 1;
let meta_sans_side: i32 = $trade.meta_i32() & MASK;

}
_ => {}
}
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;

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()) {
// (Ok(e!(bmex)), Ok(c!(btc)), Ok(c!(usd))) => {
// n_bmex += 1;
// }

// (Ok(e!(gdax)), Ok(c!(btc)), Ok(c!(usd))) => {
// gdax_total += $trade.price() * $trade.amount();
// gdax_amount += $trade.amount();
// n_gdax += 1;

// }
//
// _ => {}
//}
}}
}



+ 14
- 7
src/encoding.rs View File

@@ -183,13 +183,6 @@ impl<'a> PackedTradeData<'a> {
pub fn base(&self) -> Result<Currency, markets::crypto::Error> {
Currency::try_from(self.0[BASE_OFFSET])
}
#[inline]
pub fn ticker(&self) -> Ticker {
Ticker {
base: self.base().unwrap(),
quote: self.quote().unwrap(),
}
}

#[inline]
pub fn quote(&self) -> Result<Currency, markets::crypto::Error> {
@@ -204,6 +197,20 @@ impl<'a> PackedTradeData<'a> {
}
}

#[inline]
pub fn ticker(&self) -> Ticker {
Ticker {
base: self.base().unwrap(),
quote: self.quote().unwrap(),
}
}

#[inline]
pub unsafe fn meta_i32(&self) -> i32 {
i32::from_le_bytes((&self.0[..4]).try_into().unwrap())
}


#[inline]
pub fn time(&self) -> u64 {
u64::from_le_bytes(


Loading…
Cancel
Save