mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-28 16:18:57 +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 {}
|
||||
|
||||
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 {
|
||||
// Use the given unit for all entries.
|
||||
unit
|
||||
|
||||
@@ -11,7 +11,7 @@ use csv::WriterBuilder;
|
||||
pub struct 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![]);
|
||||
for res in results {
|
||||
// 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)]
|
||||
struct HyperfineSummary<'a> {
|
||||
results: &'a Vec<BenchmarkResult>,
|
||||
results: &'a [BenchmarkResult],
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct 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 });
|
||||
for content in output.iter_mut() {
|
||||
content.push(b'\n');
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::io::Result;
|
||||
pub struct 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 {
|
||||
// Use the given unit for all entries.
|
||||
unit
|
||||
@@ -23,7 +23,7 @@ impl Exporter for MarkdownExporter {
|
||||
Unit::Second
|
||||
};
|
||||
|
||||
let annotated_results = compute_relative_speed(&results);
|
||||
let annotated_results = compute_relative_speed(results);
|
||||
|
||||
let mut destination = start_table(unit);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ pub enum ExportType {
|
||||
/// Interface for different exporters.
|
||||
trait Exporter {
|
||||
/// 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 {
|
||||
@@ -79,7 +79,7 @@ impl ExportManager {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
file.write_all(content)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {
|
||||
}
|
||||
|
||||
pub fn compute_relative_speed<'a>(
|
||||
results: &'a Vec<BenchmarkResult>,
|
||||
results: &'a [BenchmarkResult],
|
||||
) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {
|
||||
let fastest: &BenchmarkResult = results
|
||||
.iter()
|
||||
@@ -84,7 +84,7 @@ pub fn compute_relative_speed<'a>(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn write_benchmark_comparison(results: &Vec<BenchmarkResult>) {
|
||||
pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {
|
||||
if results.len() < 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ pub fn error(message: &str) -> ! {
|
||||
|
||||
/// Runs the benchmark for the given commands
|
||||
fn run(
|
||||
commands: &Vec<Command<'_>>,
|
||||
commands: &[Command<'_>],
|
||||
options: &HyperfineOptions,
|
||||
) -> io::Result<Vec<BenchmarkResult>> {
|
||||
let shell_spawning_time =
|
||||
|
||||
Reference in new issue
Block a user