Fix errors in benchmarks

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/32/head
trivernis 3 years ago
parent 2527763494
commit 51f53e7fbe
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -3,13 +3,13 @@ use criterion::{criterion_group, criterion_main};
use criterion::{BatchSize, Criterion}; use criterion::{BatchSize, Criterion};
use std::io::Cursor; use std::io::Cursor;
use bromine::event::Event; use bromine::event::{Event, EventType};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
pub const EVENT_NAME: &str = "bench_event"; pub const EVENT_NAME: &str = "bench_event";
fn create_event_bytes_reader(data_size: usize) -> Cursor<Vec<u8>> { fn create_event_bytes_reader(data_size: usize) -> Cursor<Vec<u8>> {
let bytes = Event::new(EVENT_NAME.to_string(), vec![0u8; data_size], None) let bytes = Event::initiator(None, EVENT_NAME.to_string(), vec![0u8; data_size])
.into_bytes() .into_bytes()
.unwrap(); .unwrap();
Cursor::new(bytes) Cursor::new(bytes)

@ -6,7 +6,7 @@ use criterion::{
pub const EVENT_NAME: &str = "bench_event"; pub const EVENT_NAME: &str = "bench_event";
fn create_event(data_size: usize) -> Event { fn create_event(data_size: usize) -> Event {
Event::new(EVENT_NAME.to_string(), vec![0u8; data_size], None) Event::initiator(None, EVENT_NAME.to_string(), vec![0u8; data_size])
} }
fn event_serialization(c: &mut Criterion) { fn event_serialization(c: &mut Criterion) {

@ -41,31 +41,21 @@ impl Event {
/// Creates a new event that acts as an initiator for further response events /// Creates a new event that acts as an initiator for further response events
#[tracing::instrument(level = "trace", skip(data))] #[tracing::instrument(level = "trace", skip(data))]
#[inline] #[inline]
pub(crate) fn initiator(namespace: Option<String>, name: String, data: Vec<u8>) -> Self { pub fn initiator(namespace: Option<String>, name: String, data: Vec<u8>) -> Self {
Self::new(namespace, name, data, None, EventType::Initiator) Self::new(namespace, name, data, None, EventType::Initiator)
} }
/// Creates a new event that is a response to a previous event /// Creates a new event that is a response to a previous event
#[tracing::instrument(level = "trace", skip(data))] #[tracing::instrument(level = "trace", skip(data))]
#[inline] #[inline]
pub(crate) fn response( pub fn response(namespace: Option<String>, name: String, data: Vec<u8>, ref_id: u64) -> Self {
namespace: Option<String>,
name: String,
data: Vec<u8>,
ref_id: u64,
) -> Self {
Self::new(namespace, name, data, Some(ref_id), EventType::Response) Self::new(namespace, name, data, Some(ref_id), EventType::Response)
} }
/// Creates a new error event as a response to a previous event /// Creates a new error event as a response to a previous event
#[tracing::instrument(level = "trace", skip(data))] #[tracing::instrument(level = "trace", skip(data))]
#[inline] #[inline]
pub(crate) fn error( pub fn error(namespace: Option<String>, name: String, data: Vec<u8>, ref_id: u64) -> Self {
namespace: Option<String>,
name: String,
data: Vec<u8>,
ref_id: u64,
) -> Self {
Self::new(namespace, name, data, Some(ref_id), EventType::Error) Self::new(namespace, name, data, Some(ref_id), EventType::Error)
} }
@ -73,7 +63,7 @@ impl Event {
/// and might contain a final response payload /// and might contain a final response payload
#[tracing::instrument(level = "trace", skip(data))] #[tracing::instrument(level = "trace", skip(data))]
#[inline] #[inline]
pub(crate) fn end(namespace: Option<String>, name: String, data: Vec<u8>, ref_id: u64) -> Self { pub fn end(namespace: Option<String>, name: String, data: Vec<u8>, ref_id: u64) -> Self {
Self::new(namespace, name, data, Some(ref_id), EventType::Response) Self::new(namespace, name, data, Some(ref_id), EventType::Response)
} }

Loading…
Cancel
Save