mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 09:01:25 +00:00
Use slices instead of borrowed vectors
This commit is contained in:
1 parent
f3f8c9ca98
commit
c0ada7d044
7 files changed
+11
-11
No files matched your search
@@ -10,7 +10,7 @@ use std::io::Result;
|
|||||||
pub struct AsciidocExporter {}
|
pub struct AsciidocExporter {}
|
||||||
|
|
||||||
impl Exporter for AsciidocExporter {
|
impl Exporter for AsciidocExporter {
|
||||||
fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>> {
|
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {
|
||||||
let unit = if let Some(unit) = unit {
|
let unit = if let Some(unit) = unit {
|
||||||
// Use the given unit for all entries.
|
// Use the given unit for all entries.
|
||||||
unit
|
unit
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use csv::WriterBuilder;
|
|||||||
pub struct CsvExporter {}
|
pub struct CsvExporter {}
|
||||||
|
|
||||||
impl Exporter for CsvExporter {
|
impl Exporter for CsvExporter {
|
||||||
fn serialize(&self, results: &Vec<BenchmarkResult>, _unit: Option<Unit>) -> Result<Vec<u8>> {
|
fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {
|
||||||
let mut writer = WriterBuilder::new().from_writer(vec![]);
|
let mut writer = WriterBuilder::new().from_writer(vec![]);
|
||||||
for res in results {
|
for res in results {
|
||||||
// The list of times cannot be exported to the CSV file - remove it:
|
// The list of times cannot be exported to the CSV file - remove it:
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ use serde_json::to_vec_pretty;
|
|||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct HyperfineSummary<'a> {
|
struct HyperfineSummary<'a> {
|
||||||
results: &'a Vec<BenchmarkResult>,
|
results: &'a [BenchmarkResult],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct JsonExporter {}
|
pub struct JsonExporter {}
|
||||||
|
|
||||||
impl Exporter for JsonExporter {
|
impl Exporter for JsonExporter {
|
||||||
fn serialize(&self, results: &Vec<BenchmarkResult>, _unit: Option<Unit>) -> Result<Vec<u8>> {
|
fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {
|
||||||
let mut output = to_vec_pretty(&HyperfineSummary { results });
|
let mut output = to_vec_pretty(&HyperfineSummary { results });
|
||||||
for content in output.iter_mut() {
|
for content in output.iter_mut() {
|
||||||
content.push(b'\n');
|
content.push(b'\n');
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use std::io::Result;
|
|||||||
pub struct MarkdownExporter {}
|
pub struct MarkdownExporter {}
|
||||||
|
|
||||||
impl Exporter for MarkdownExporter {
|
impl Exporter for MarkdownExporter {
|
||||||
fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>> {
|
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {
|
||||||
let unit = if let Some(unit) = unit {
|
let unit = if let Some(unit) = unit {
|
||||||
// Use the given unit for all entries.
|
// Use the given unit for all entries.
|
||||||
unit
|
unit
|
||||||
@@ -23,7 +23,7 @@ impl Exporter for MarkdownExporter {
|
|||||||
Unit::Second
|
Unit::Second
|
||||||
};
|
};
|
||||||
|
|
||||||
let annotated_results = compute_relative_speed(&results);
|
let annotated_results = compute_relative_speed(results);
|
||||||
|
|
||||||
let mut destination = start_table(unit);
|
let mut destination = start_table(unit);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ pub enum ExportType {
|
|||||||
/// Interface for different exporters.
|
/// Interface for different exporters.
|
||||||
trait Exporter {
|
trait Exporter {
|
||||||
/// Export the given entries in the serialized form.
|
/// Export the given entries in the serialized form.
|
||||||
fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>>;
|
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExporterWithFilename {
|
struct ExporterWithFilename {
|
||||||
@@ -79,7 +79,7 @@ impl ExportManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the given content to a file with the specified name
|
/// Write the given content to a file with the specified name
|
||||||
fn write_to_file(filename: &String, content: &Vec<u8>) -> Result<()> {
|
fn write_to_file(filename: &String, content: &[u8]) -> Result<()> {
|
||||||
let mut file = File::create(filename)?;
|
let mut file = File::create(filename)?;
|
||||||
file.write_all(content)
|
file.write_all(content)
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_relative_speed<'a>(
|
pub fn compute_relative_speed<'a>(
|
||||||
results: &'a Vec<BenchmarkResult>,
|
results: &'a [BenchmarkResult],
|
||||||
) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {
|
) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {
|
||||||
let fastest: &BenchmarkResult = results
|
let fastest: &BenchmarkResult = results
|
||||||
.iter()
|
.iter()
|
||||||
@@ -84,7 +84,7 @@ pub fn compute_relative_speed<'a>(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_benchmark_comparison(results: &Vec<BenchmarkResult>) {
|
pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {
|
||||||
if results.len() < 2 {
|
if results.len() < 2 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ pub fn error(message: &str) -> ! {
|
|||||||
|
|
||||||
/// Runs the benchmark for the given commands
|
/// Runs the benchmark for the given commands
|
||||||
fn run(
|
fn run(
|
||||||
commands: &Vec<Command<'_>>,
|
commands: &[Command<'_>],
|
||||||
options: &HyperfineOptions,
|
options: &HyperfineOptions,
|
||||||
) -> io::Result<Vec<BenchmarkResult>> {
|
) -> io::Result<Vec<BenchmarkResult>> {
|
||||||
let shell_spawning_time =
|
let shell_spawning_time =
|
||||||
|
|||||||
Reference in new issue
Block a user