mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-01-08 19:25:24 +00:00
Improve Benchmarks #51
This commit is contained in:
parent
096957b167
commit
ce04223ec4
5 changed files with 84 additions and 52 deletions
|
@ -36,8 +36,5 @@ version-sync = "0.9"
|
||||||
criterion = "0.3.1"
|
criterion = "0.3.1"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "parse"
|
name = "bench_main"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[profile.bench]
|
|
||||||
debug = true
|
|
||||||
|
|
7
benches/bench_main.rs
Normal file
7
benches/bench_main.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use criterion::criterion_main;
|
||||||
|
|
||||||
|
mod benchmarks;
|
||||||
|
|
||||||
|
criterion_main! {
|
||||||
|
benchmarks::media_playlist::benches,
|
||||||
|
}
|
75
benches/benchmarks/media_playlist.rs
Normal file
75
benches/benchmarks/media_playlist.rs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use criterion::{black_box, criterion_group, Criterion, Throughput};
|
||||||
|
|
||||||
|
use hls_m3u8::tags::{ExtXDateRange, ExtXProgramDateTime};
|
||||||
|
use hls_m3u8::types::Value;
|
||||||
|
use hls_m3u8::{MediaPlaylist, MediaSegment};
|
||||||
|
|
||||||
|
fn create_manifest_data() -> Vec<u8> {
|
||||||
|
let mut builder = MediaPlaylist::builder();
|
||||||
|
|
||||||
|
builder.media_sequence(826176645);
|
||||||
|
builder.has_independent_segments(true);
|
||||||
|
builder.target_duration(Duration::from_secs(2));
|
||||||
|
|
||||||
|
for i in 0..4000 {
|
||||||
|
let mut seg = MediaSegment::builder();
|
||||||
|
seg.duration(Duration::from_secs_f64(1.92)).uri(format!(
|
||||||
|
"avc_unencrypted_global-video=3000000-{}.ts?variant=italy",
|
||||||
|
826176659 + i
|
||||||
|
));
|
||||||
|
|
||||||
|
if i == 0 {
|
||||||
|
seg.program_date_time(ExtXProgramDateTime::new("2020-04-07T11:32:38Z"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if i % 100 == 0 {
|
||||||
|
seg.date_range(
|
||||||
|
ExtXDateRange::builder()
|
||||||
|
.id(format!("date_id_{}", i / 100))
|
||||||
|
.start_date("2020-04-07T11:40:02.040000Z")
|
||||||
|
.duration(Duration::from_secs_f64(65.2))
|
||||||
|
.insert_client_attribute(
|
||||||
|
"SCTE35-OUT",
|
||||||
|
Value::Hex(
|
||||||
|
hex::decode(concat!(
|
||||||
|
"FC30250000",
|
||||||
|
"0000000000",
|
||||||
|
"FFF0140500",
|
||||||
|
"001C207FEF",
|
||||||
|
"FE0030E3A0",
|
||||||
|
"FE005989E0",
|
||||||
|
"0001000000",
|
||||||
|
"0070BA5ABF"
|
||||||
|
))
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.push_segment(seg.build().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.build().unwrap().to_string().into_bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
|
let data = String::from_utf8(create_manifest_data()).unwrap();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group("MediaPlaylist::from_str");
|
||||||
|
|
||||||
|
group.throughput(Throughput::Bytes(data.len() as u64));
|
||||||
|
|
||||||
|
group.bench_function("MediaPlaylist::from_str", |b| {
|
||||||
|
b.iter(|| MediaPlaylist::from_str(black_box(&data)).unwrap());
|
||||||
|
});
|
||||||
|
|
||||||
|
group.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, criterion_benchmark);
|
1
benches/benchmarks/mod.rs
Normal file
1
benches/benchmarks/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod media_playlist;
|
|
@ -1,48 +0,0 @@
|
||||||
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
|
|
||||||
use hls_m3u8;
|
|
||||||
use hls_m3u8::tags::{ExtXDateRange, ExtXProgramDateTime};
|
|
||||||
use hls_m3u8::types::Value;
|
|
||||||
use hls_m3u8::{MediaPlaylist, MediaSegment};
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
fn create_manifest_data() -> Vec<u8> {
|
|
||||||
let mut builder = MediaPlaylist::builder();
|
|
||||||
builder.media_sequence(826176645);
|
|
||||||
builder.has_independent_segments(true);
|
|
||||||
builder.target_duration(std::time::Duration::from_secs(2));
|
|
||||||
for i in 0..4000 {
|
|
||||||
let mut seg = MediaSegment::builder();
|
|
||||||
seg.duration(std::time::Duration::from_secs_f64(1.92))
|
|
||||||
.uri(format!(
|
|
||||||
"avc_unencrypted_global-video=3000000-{}.ts?variant=italy",
|
|
||||||
826176659 + i
|
|
||||||
));
|
|
||||||
if i == 0 {
|
|
||||||
seg.program_date_time(ExtXProgramDateTime::new("2020-04-07T11:32:38Z"));
|
|
||||||
}
|
|
||||||
if i % 100 == 0 {
|
|
||||||
let mut date_range =
|
|
||||||
ExtXDateRange::new(format!("{}", i / 100), "2020-04-07T11:40:02.040000Z");
|
|
||||||
date_range.duration = Some(std::time::Duration::from_secs_f64(65.2));
|
|
||||||
date_range.client_attributes.insert("SCTE35-OUT".to_string(), Value::Hex(hex::decode("FC302500000000000000FFF0140500001C207FEFFE0030E3A0FE005989E000010000000070BA5ABF").unwrap()));
|
|
||||||
seg.date_range(date_range);
|
|
||||||
}
|
|
||||||
builder.push_segment(seg.build().unwrap());
|
|
||||||
}
|
|
||||||
builder.build().unwrap().to_string().into_bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn criterion_benchmark(c: &mut Criterion) {
|
|
||||||
let buf = create_manifest_data();
|
|
||||||
let mut group = c.benchmark_group("parser");
|
|
||||||
group.throughput(Throughput::Bytes(buf.len() as u64));
|
|
||||||
group.bench_function("throughput", |b| {
|
|
||||||
b.iter(|| {
|
|
||||||
let buf = String::from_utf8_lossy(&buf);
|
|
||||||
hls_m3u8::MediaPlaylist::from_str(&buf).unwrap()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches, criterion_benchmark);
|
|
||||||
criterion_main!(benches);
|
|
Loading…
Reference in a new issue