-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(bench): Dedup bench code and reduce variance between runs #210
Open
luukvanderduim
wants to merge
2
commits into
main
Choose a base branch
from
reduce-bench-variance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
/atspi/*.bin | ||
*.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
use atspi::events::document::{ | ||
AttributesChangedEvent as DocumentAttributesChangedEvent, ContentChangedEvent, | ||
LoadCompleteEvent, LoadStoppedEvent, PageChangedEvent, ReloadEvent, | ||
}; | ||
use atspi::events::focus::FocusEvent; | ||
use atspi::events::mouse::{AbsEvent, ButtonEvent, RelEvent}; | ||
use atspi::events::object::{ | ||
ActiveDescendantChangedEvent, AnnouncementEvent, AttributesChangedEvent, BoundsChangedEvent, | ||
ChildrenChangedEvent, ColumnDeletedEvent, ColumnInsertedEvent, ColumnReorderedEvent, | ||
LinkSelectedEvent, ModelChangedEvent, PropertyChangeEvent, RowDeletedEvent, RowInsertedEvent, | ||
RowReorderedEvent, SelectionChangedEvent, TextAttributesChangedEvent, TextBoundsChangedEvent, | ||
TextCaretMovedEvent, TextChangedEvent, TextSelectionChangedEvent, VisibleDataChangedEvent, | ||
}; | ||
use atspi::events::terminal::{ | ||
ApplicationChangedEvent, CharWidthChangedEvent, ColumnCountChangedEvent, LineChangedEvent, | ||
LineCountChangedEvent, | ||
}; | ||
use atspi::events::window::{ | ||
ActivateEvent, CloseEvent, CreateEvent, DeactivateEvent, DesktopCreateEvent, | ||
DesktopDestroyEvent, DestroyEvent, LowerEvent, MaximizeEvent, MinimizeEvent, MoveEvent, | ||
PropertyChangeEvent as WindowPropertyChangeEvent, RaiseEvent, ReparentEvent, ResizeEvent, | ||
RestoreEvent, RestyleEvent, ShadeEvent, UUshadeEvent, | ||
}; | ||
use std::{ | ||
fs::File, | ||
io::{BufReader, BufWriter, Read, Write}, | ||
}; | ||
use zbus::{ | ||
zvariant::{ | ||
serialized::{Context, Data, Format}, | ||
Endian, | ||
}, | ||
Message, | ||
}; | ||
|
||
pub fn vec_of_all_atspi_messages() -> Vec<Message> { | ||
vec![ | ||
// document events | ||
DocumentAttributesChangedEvent::default().try_into().unwrap(), | ||
ContentChangedEvent::default().try_into().unwrap(), | ||
LoadCompleteEvent::default().try_into().unwrap(), | ||
LoadStoppedEvent::default().try_into().unwrap(), | ||
PageChangedEvent::default().try_into().unwrap(), | ||
ReloadEvent::default().try_into().unwrap(), | ||
// focus events | ||
FocusEvent::default().try_into().unwrap(), | ||
// mouse events | ||
AbsEvent::default().try_into().unwrap(), | ||
ButtonEvent::default().try_into().unwrap(), | ||
RelEvent::default().try_into().unwrap(), | ||
// object events | ||
ActiveDescendantChangedEvent::default().try_into().unwrap(), | ||
AnnouncementEvent::default().try_into().unwrap(), | ||
AttributesChangedEvent::default().try_into().unwrap(), | ||
BoundsChangedEvent::default().try_into().unwrap(), | ||
ChildrenChangedEvent::default().try_into().unwrap(), | ||
ColumnDeletedEvent::default().try_into().unwrap(), | ||
ColumnInsertedEvent::default().try_into().unwrap(), | ||
ColumnReorderedEvent::default().try_into().unwrap(), | ||
LinkSelectedEvent::default().try_into().unwrap(), | ||
ModelChangedEvent::default().try_into().unwrap(), | ||
PropertyChangeEvent::default().try_into().unwrap(), | ||
RowDeletedEvent::default().try_into().unwrap(), | ||
RowInsertedEvent::default().try_into().unwrap(), | ||
RowReorderedEvent::default().try_into().unwrap(), | ||
SelectionChangedEvent::default().try_into().unwrap(), | ||
TextAttributesChangedEvent::default().try_into().unwrap(), | ||
TextBoundsChangedEvent::default().try_into().unwrap(), | ||
TextCaretMovedEvent::default().try_into().unwrap(), | ||
TextChangedEvent::default().try_into().unwrap(), | ||
TextSelectionChangedEvent::default().try_into().unwrap(), | ||
VisibleDataChangedEvent::default().try_into().unwrap(), | ||
// terminal events | ||
ApplicationChangedEvent::default().try_into().unwrap(), | ||
CharWidthChangedEvent::default().try_into().unwrap(), | ||
ColumnCountChangedEvent::default().try_into().unwrap(), | ||
LineChangedEvent::default().try_into().unwrap(), | ||
LineCountChangedEvent::default().try_into().unwrap(), | ||
// window events | ||
ActivateEvent::default().try_into().unwrap(), | ||
CloseEvent::default().try_into().unwrap(), | ||
CreateEvent::default().try_into().unwrap(), | ||
DeactivateEvent::default().try_into().unwrap(), | ||
DesktopCreateEvent::default().try_into().unwrap(), | ||
DesktopDestroyEvent::default().try_into().unwrap(), | ||
DestroyEvent::default().try_into().unwrap(), | ||
LowerEvent::default().try_into().unwrap(), | ||
MaximizeEvent::default().try_into().unwrap(), | ||
MinimizeEvent::default().try_into().unwrap(), | ||
MoveEvent::default().try_into().unwrap(), | ||
WindowPropertyChangeEvent::default().try_into().unwrap(), | ||
RaiseEvent::default().try_into().unwrap(), | ||
ReparentEvent::default().try_into().unwrap(), | ||
ResizeEvent::default().try_into().unwrap(), | ||
RestoreEvent::default().try_into().unwrap(), | ||
RestyleEvent::default().try_into().unwrap(), | ||
ShadeEvent::default().try_into().unwrap(), | ||
UUshadeEvent::default().try_into().unwrap(), | ||
] | ||
} | ||
|
||
pub fn generate_n_messages_rnd(n: usize) -> Vec<Message> { | ||
let all_messages = vec_of_all_atspi_messages(); | ||
let mut messages: Vec<Message> = Vec::with_capacity(n); | ||
for _ in 0..n { | ||
let random_msg = all_messages[fastrand::usize(..all_messages.len())].clone(); | ||
messages.push(random_msg); | ||
} | ||
messages | ||
} | ||
|
||
pub fn write_messages_to_file(messages: Vec<Message>, file: &str) { | ||
let file = File::create(file).unwrap(); | ||
let mut writer = BufWriter::new(file); | ||
|
||
for msg in messages { | ||
let bytes = msg.data().bytes(); | ||
let len = bytes.len() as u32; | ||
writer.write_all(&len.to_ne_bytes()).unwrap(); | ||
writer.write_all(bytes).unwrap(); | ||
} | ||
writer.flush().unwrap(); | ||
} | ||
|
||
pub fn read_messages_from_file(file_path: &str) -> Vec<Message> { | ||
let file = File::open(file_path).unwrap(); | ||
let mut slices = Vec::new(); | ||
let mut reader = BufReader::new(file); | ||
|
||
loop { | ||
let mut buf = [0; 4]; | ||
let n = reader.read(&mut buf).unwrap(); | ||
if n == 0 { | ||
break; | ||
} | ||
let len = u32::from_ne_bytes(buf); | ||
|
||
let mut buf = vec![0; len as usize]; | ||
reader.read_exact(&mut buf).unwrap(); | ||
slices.push(buf); | ||
} | ||
|
||
let context = Context::new(Format::default(), Endian::native(), 0); | ||
|
||
slices | ||
.into_iter() | ||
.map(|slice| { | ||
let data = Data::new(slice, context); | ||
unsafe { Message::from_bytes(data).unwrap() } | ||
}) | ||
.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy complained because of a new lint: needless_lazy_evaluation