mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Some renamings and documentation updates
This commit is contained in:
1 parent
c59110d652
commit
aabe1331a2
4 files changed
+32
-28
No files matched your search
+23
-19
@@ -9,28 +9,33 @@ use std::fs::File;
|
||||
|
||||
use hyperfine::internal::Second;
|
||||
|
||||
/// The ExportEntry is the main set of values that will
|
||||
/// be exported to files when requested.
|
||||
/// Set of values that will be exported.
|
||||
#[derive(Debug, Default, Clone, Serialize)]
|
||||
pub struct ExportEntry {
|
||||
/// The command that was run
|
||||
command: String,
|
||||
|
||||
/// The mean run time
|
||||
mean: Second,
|
||||
|
||||
/// The standard deviation of all run times
|
||||
stddev: Second,
|
||||
|
||||
/// Time spend in user space
|
||||
user: Second,
|
||||
|
||||
/// Time spent in system space
|
||||
system: Second,
|
||||
|
||||
/// Min time measured
|
||||
min: Second,
|
||||
|
||||
/// Max time measured
|
||||
max: Second,
|
||||
}
|
||||
|
||||
impl ExportEntry {
|
||||
/// Create a new ExportEntry with the given values
|
||||
/// Create a new entry with the given values.
|
||||
pub fn new(
|
||||
command: String,
|
||||
mean: Second,
|
||||
@@ -52,21 +57,20 @@ impl ExportEntry {
|
||||
}
|
||||
}
|
||||
|
||||
/// The ResultExportType enum is used to denote the desired form
|
||||
/// of exporter to use for a given file.
|
||||
/// The desired form of exporter to use for a given file.
|
||||
#[derive(Clone)]
|
||||
pub enum ResultExportType {
|
||||
/// Export to a csv file with the provided name
|
||||
pub enum ExportType {
|
||||
/// CSV (comma separated values) format
|
||||
Csv(String),
|
||||
/// Export to a JSON file
|
||||
|
||||
/// JSON format
|
||||
Json(String),
|
||||
}
|
||||
|
||||
/// A ResultExporter is responsible for writing all results to the
|
||||
/// appropriate file
|
||||
trait ResultExporter {
|
||||
/// Write all entries to the target destination
|
||||
fn write(&self, values: &Vec<ExportEntry>) -> Result<Vec<u8>>;
|
||||
/// Interface for different exporters.
|
||||
trait Exporter {
|
||||
/// Export the given entries in the serialized form.
|
||||
fn serialize(&self, values: &Vec<ExportEntry>) -> Result<Vec<u8>>;
|
||||
}
|
||||
|
||||
/// Create a new ExportManager
|
||||
@@ -79,24 +83,24 @@ pub fn create_export_manager() -> ExportManager {
|
||||
/// The ExportManager handles the management of multiple file
|
||||
/// exporters.
|
||||
pub struct ExportManager {
|
||||
exporters: Vec<ResultExportType>,
|
||||
exporters: Vec<ExportType>,
|
||||
}
|
||||
|
||||
impl ExportManager {
|
||||
/// Add an additional exporter to the ExportManager
|
||||
pub fn add_exporter(&mut self, for_type: ResultExportType) {
|
||||
pub fn add_exporter(&mut self, for_type: ExportType) {
|
||||
self.exporters.push(for_type);
|
||||
}
|
||||
|
||||
/// Write the given results to all Exporters contained within this manager
|
||||
pub fn write_results(&self, to_write: Vec<ExportEntry>) -> Result<()> {
|
||||
for exp in &self.exporters {
|
||||
let (exporter, filename): (Box<ResultExporter>, &str) = match exp {
|
||||
&ResultExportType::Csv(ref file) => (Box::from(CsvExporter::new()), file),
|
||||
&ResultExportType::Json(ref file) => (Box::from(JsonExporter::new()), file),
|
||||
let (exporter, filename): (Box<Exporter>, &str) = match exp {
|
||||
&ExportType::Csv(ref file) => (Box::from(CsvExporter::new()), file),
|
||||
&ExportType::Json(ref file) => (Box::from(JsonExporter::new()), file),
|
||||
};
|
||||
|
||||
let file_content = exporter.write(&to_write)?;
|
||||
let file_content = exporter.serialize(&to_write)?;
|
||||
write_to_file(filename, file_content)?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user