Skip to content

Commit

Permalink
add benchmark for GimpGradient
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Sep 13, 2022
1 parent 8dae946 commit 71225b2
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ harness = false
[[bench]]
name = "preset"
harness = false

[[bench]]
name = "gimp"
harness = false
25 changes: 25 additions & 0 deletions benches/gimp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use colorgrad::Color;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::io::BufReader;

const GGR_STR: &'static str = include_str!("../examples/ggr/My_Gradient.ggr");

const POSITIONS: [f64; 3] = [0.03, 0.5, 0.97];

fn bench_gimp_gradient(c: &mut Criterion) {
let fg_color = Color::new(0.0, 0.0, 0.0, 1.0);
let bg_color = Color::new(1.0, 1.0, 1.0, 1.0);
let (gradient, _) =
colorgrad::parse_ggr(BufReader::new(GGR_STR.as_bytes()), &fg_color, &bg_color).unwrap();

for pos in POSITIONS {
c.bench_function(&format!("GimpGradient t={pos}"), |b| {
b.iter(|| {
gradient.at(black_box(pos));
})
});
}
}

criterion_group!(gimp_gradient, bench_gimp_gradient,);
criterion_main!(gimp_gradient);
103 changes: 103 additions & 0 deletions examples/ggr/My_Gradient.ggr
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
GIMP Gradient
Name: My Gradient
100
0.000000 0.005000 0.010000 1.000000 1.000000 0.000000 1.000000 1.000000 0.963882 0.000575 1.000000 0 0 0 0
0.010000 0.015000 0.020000 1.000000 0.963882 0.000575 1.000000 1.000000 0.927759 0.003080 1.000000 0 0 0 0
0.020000 0.025000 0.030000 1.000000 0.927759 0.003080 1.000000 1.000000 0.891717 0.009192 1.000000 0 0 0 0
0.030000 0.035000 0.040000 1.000000 0.891717 0.009192 1.000000 1.000000 0.855847 0.020315 1.000000 0 0 0 0
0.040000 0.045000 0.050000 1.000000 0.855847 0.020315 1.000000 1.000000 0.820240 0.037596 1.000000 0 0 0 0
0.050000 0.055000 0.060000 1.000000 0.820240 0.037596 1.000000 1.000000 0.784997 0.059007 1.000000 0 0 0 0
0.060000 0.065000 0.070000 1.000000 0.784997 0.059007 1.000000 1.000000 0.750223 0.080719 1.000000 0 0 0 0
0.070000 0.075000 0.080000 1.000000 0.750223 0.080719 1.000000 1.000000 0.716034 0.102592 1.000000 0 0 0 0
0.080000 0.085000 0.090000 1.000000 0.716034 0.102592 1.000000 1.000000 0.682551 0.124545 1.000000 0 0 0 0
0.090000 0.095000 0.100000 1.000000 0.682551 0.124545 1.000000 1.000000 0.649910 0.146528 1.000000 0 0 0 0
0.100000 0.105000 0.110000 1.000000 0.649910 0.146528 1.000000 1.000000 0.618257 0.168523 1.000000 0 0 0 0
0.110000 0.115000 0.120000 1.000000 0.618257 0.168523 1.000000 1.000000 0.587753 0.190532 1.000000 0 0 0 0
0.120000 0.125000 0.130000 1.000000 0.587753 0.190532 1.000000 0.993836 0.558569 0.212579 1.000000 0 0 0 0
0.130000 0.135000 0.140000 0.993836 0.558569 0.212579 1.000000 0.980974 0.530893 0.234712 1.000000 0 0 0 0
0.140000 0.145000 0.150000 0.980974 0.530893 0.234712 1.000000 0.966267 0.504921 0.256991 1.000000 0 0 0 0
0.150000 0.155000 0.160000 0.966267 0.504921 0.256991 1.000000 0.949699 0.480853 0.279496 1.000000 0 0 0 0
0.160000 0.165000 0.170000 0.949699 0.480853 0.279496 1.000000 0.931250 0.458891 0.302328 1.000000 0 0 0 0
0.170000 0.175000 0.180000 0.931250 0.458891 0.302328 1.000000 0.910893 0.439220 0.325599 1.000000 0 0 0 0
0.180000 0.185000 0.190000 0.910893 0.439220 0.325599 1.000000 0.888597 0.421996 0.349444 1.000000 0 0 0 0
0.190000 0.195000 0.200000 0.888597 0.421996 0.349444 1.000000 0.864317 0.407330 0.374009 1.000000 0 0 0 0
0.200000 0.205000 0.210000 0.864317 0.407330 0.374009 1.000000 0.838069 0.395225 0.399362 1.000000 0 0 0 0
0.210000 0.215000 0.220000 0.838069 0.395225 0.399362 1.000000 0.810129 0.385462 0.425243 1.000000 0 0 0 0
0.220000 0.225000 0.230000 0.810129 0.385462 0.425243 1.000000 0.780816 0.377745 0.451403 1.000000 0 0 0 0
0.230000 0.235000 0.240000 0.780816 0.377745 0.451403 1.000000 0.750425 0.371769 0.477670 1.000000 0 0 0 0
0.240000 0.245000 0.250000 0.750425 0.371769 0.477670 1.000000 0.719224 0.367238 0.503914 1.000000 0 0 0 0
0.250000 0.255000 0.260000 0.719224 0.367238 0.503914 1.000000 0.687457 0.363891 0.530025 1.000000 0 0 0 0
0.260000 0.265000 0.270000 0.687457 0.363891 0.530025 1.000000 0.655341 0.361514 0.555900 1.000000 0 0 0 0
0.270000 0.275000 0.280000 0.655341 0.361514 0.555900 1.000000 0.623063 0.359951 0.581432 1.000000 0 0 0 0
0.280000 0.285000 0.290000 0.623063 0.359951 0.581432 1.000000 0.590778 0.359111 0.606505 1.000000 0 0 0 0
0.290000 0.295000 0.300000 0.590778 0.359111 0.606505 1.000000 0.558604 0.358970 0.630988 1.000000 0 0 0 0
0.300000 0.305000 0.310000 0.558604 0.358970 0.630988 1.000000 0.526618 0.359567 0.654737 1.000000 0 0 0 0
0.310000 0.315000 0.320000 0.526618 0.359567 0.654737 1.000000 0.494850 0.361006 0.677589 1.000000 0 0 0 0
0.320000 0.325000 0.330000 0.494850 0.361006 0.677589 1.000000 0.463275 0.363445 0.699366 1.000000 0 0 0 0
0.330000 0.335000 0.340000 0.463275 0.363445 0.699366 1.000000 0.431802 0.367086 0.719870 1.000000 0 0 0 0
0.340000 0.345000 0.350000 0.431802 0.367086 0.719870 1.000000 0.400264 0.372163 0.738887 1.000000 0 0 0 0
0.350000 0.355000 0.360000 0.400264 0.372163 0.738887 1.000000 0.368399 0.378924 0.756186 1.000000 0 0 0 0
0.360000 0.365000 0.370000 0.368399 0.378924 0.756186 1.000000 0.335827 0.387616 0.771519 1.000000 0 0 0 0
0.370000 0.375000 0.380000 0.335827 0.387616 0.771519 1.000000 0.302004 0.398459 0.784617 1.000000 0 0 0 0
0.380000 0.385000 0.390000 0.302004 0.398459 0.784617 1.000000 0.266138 0.411634 0.795195 1.000000 0 0 0 0
0.390000 0.395000 0.400000 0.266138 0.411634 0.795195 1.000000 0.227011 0.427266 0.802945 1.000000 0 0 0 0
0.400000 0.405000 0.410000 0.227011 0.427266 0.802945 1.000000 0.182359 0.445349 0.807616 1.000000 0 0 0 0
0.410000 0.415000 0.420000 0.182359 0.445349 0.807616 1.000000 0.126319 0.465544 0.809257 1.000000 0 0 0 0
0.420000 0.425000 0.430000 0.126319 0.465544 0.809257 1.000000 0.029653 0.487426 0.807983 1.000000 0 0 0 0
0.430000 0.435000 0.440000 0.029653 0.487426 0.807983 1.000000 0.000000 0.510578 0.803899 1.000000 0 0 0 0
0.440000 0.445000 0.450000 0.000000 0.510578 0.803899 1.000000 0.000000 0.534600 0.797102 1.000000 0 0 0 0
0.450000 0.455000 0.460000 0.000000 0.534600 0.797102 1.000000 0.000000 0.559119 0.787684 1.000000 0 0 0 0
0.460000 0.465000 0.470000 0.000000 0.559119 0.787684 1.000000 0.000000 0.583785 0.775735 1.000000 0 0 0 0
0.470000 0.475000 0.480000 0.000000 0.583785 0.775735 1.000000 0.000000 0.608271 0.761341 1.000000 0 0 0 0
0.480000 0.485000 0.490000 0.000000 0.608271 0.761341 1.000000 0.000000 0.632273 0.744590 1.000000 0 0 0 0
0.490000 0.495000 0.500000 0.000000 0.632273 0.744590 1.000000 0.000000 0.655501 0.725570 1.000000 0 0 0 0
0.500000 0.505000 0.510000 0.000000 0.655501 0.725570 1.000000 0.000000 0.677680 0.704374 1.000000 0 0 0 0
0.510000 0.515000 0.520000 0.000000 0.677680 0.704374 1.000000 0.000000 0.698544 0.681102 1.000000 0 0 0 0
0.520000 0.525000 0.530000 0.000000 0.698544 0.681102 1.000000 0.000000 0.717838 0.655863 1.000000 0 0 0 0
0.530000 0.535000 0.540000 0.000000 0.717838 0.655863 1.000000 0.000000 0.735310 0.628782 1.000000 0 0 0 0
0.540000 0.545000 0.550000 0.000000 0.735310 0.628782 1.000000 0.053837 0.750716 0.600001 1.000000 0 0 0 0
0.550000 0.555000 0.560000 0.053837 0.750716 0.600001 1.000000 0.175596 0.763812 0.569693 1.000000 0 0 0 0
0.560000 0.565000 0.570000 0.175596 0.763812 0.569693 1.000000 0.252829 0.774359 0.538069 1.000000 0 0 0 0
0.570000 0.575000 0.580000 0.252829 0.774359 0.538069 1.000000 0.317592 0.782118 0.505394 1.000000 0 0 0 0
0.580000 0.585000 0.590000 0.317592 0.782118 0.505394 1.000000 0.375782 0.786851 0.472009 1.000000 0 0 0 0
0.590000 0.595000 0.600000 0.375782 0.786851 0.472009 1.000000 0.429506 0.788322 0.438362 1.000000 0 0 0 0
0.600000 0.605000 0.610000 0.429506 0.788322 0.438362 1.000000 0.479615 0.786358 0.404945 1.000000 0 0 0 0
0.610000 0.615000 0.620000 0.479615 0.786358 0.404945 1.000000 0.526327 0.781054 0.371930 1.000000 0 0 0 0
0.620000 0.625000 0.630000 0.526327 0.781054 0.371930 1.000000 0.569683 0.772564 0.339402 1.000000 0 0 0 0
0.630000 0.635000 0.640000 0.569683 0.772564 0.339402 1.000000 0.609671 0.761047 0.307444 1.000000 0 0 0 0
0.640000 0.645000 0.650000 0.609671 0.761047 0.307444 1.000000 0.646242 0.746658 0.276138 1.000000 0 0 0 0
0.650000 0.655000 0.660000 0.646242 0.746658 0.276138 1.000000 0.679336 0.729556 0.245569 1.000000 0 0 0 0
0.660000 0.665000 0.670000 0.679336 0.729556 0.245569 1.000000 0.708882 0.709905 0.215819 1.000000 0 0 0 0
0.670000 0.675000 0.680000 0.708882 0.709905 0.215819 1.000000 0.734805 0.687871 0.186972 1.000000 0 0 0 0
0.680000 0.685000 0.690000 0.734805 0.687871 0.186972 1.000000 0.757032 0.663625 0.159114 1.000000 0 0 0 0
0.690000 0.695000 0.700000 0.757032 0.663625 0.159114 1.000000 0.775492 0.637344 0.132330 1.000000 0 0 0 0
0.700000 0.705000 0.710000 0.775492 0.637344 0.132330 1.000000 0.790118 0.609213 0.106712 1.000000 0 0 0 0
0.710000 0.715000 0.720000 0.790118 0.609213 0.106712 1.000000 0.800850 0.579424 0.082352 1.000000 0 0 0 0
0.720000 0.725000 0.730000 0.800850 0.579424 0.082352 1.000000 0.807633 0.548181 0.059355 1.000000 0 0 0 0
0.730000 0.735000 0.740000 0.807633 0.548181 0.059355 1.000000 0.810421 0.515697 0.037851 1.000000 0 0 0 0
0.740000 0.745000 0.750000 0.810421 0.515697 0.037851 1.000000 0.809176 0.482203 0.021235 1.000000 0 0 0 0
0.750000 0.755000 0.760000 0.809176 0.482203 0.021235 1.000000 0.803868 0.447946 0.010757 1.000000 0 0 0 0
0.760000 0.765000 0.770000 0.803868 0.447946 0.010757 1.000000 0.794478 0.413197 0.004787 1.000000 0 0 0 0
0.770000 0.775000 0.780000 0.794478 0.413197 0.004787 1.000000 0.780997 0.378255 0.001887 1.000000 0 0 0 0
0.780000 0.785000 0.790000 0.780997 0.378255 0.001887 1.000000 0.763423 0.343462 0.000826 1.000000 0 0 0 0
0.790000 0.795000 0.800000 0.763423 0.343462 0.000826 1.000000 0.741772 0.309207 0.000587 1.000000 0 0 0 0
0.800000 0.805000 0.810000 0.741772 0.309207 0.000587 1.000000 0.716125 0.275883 0.000482 1.000000 0 0 0 0
0.810000 0.815000 0.820000 0.716125 0.275883 0.000482 1.000000 0.686799 0.243672 0.000388 1.000000 0 0 0 0
0.820000 0.825000 0.830000 0.686799 0.243672 0.000388 1.000000 0.654155 0.212687 0.000307 1.000000 0 0 0 0
0.830000 0.835000 0.840000 0.654155 0.212687 0.000307 1.000000 0.618543 0.183038 0.000237 1.000000 0 0 0 0
0.840000 0.845000 0.850000 0.618543 0.183038 0.000237 1.000000 0.580307 0.154823 0.000179 1.000000 0 0 0 0
0.850000 0.855000 0.860000 0.580307 0.154823 0.000179 1.000000 0.539786 0.128133 0.000132 1.000000 0 0 0 0
0.860000 0.865000 0.870000 0.539786 0.128133 0.000132 1.000000 0.497313 0.103050 0.000094 1.000000 0 0 0 0
0.870000 0.875000 0.880000 0.497313 0.103050 0.000094 1.000000 0.453225 0.079649 0.000065 1.000000 0 0 0 0
0.880000 0.885000 0.890000 0.453225 0.079649 0.000065 1.000000 0.407857 0.057995 0.000043 1.000000 0 0 0 0
0.890000 0.895000 0.900000 0.407857 0.057995 0.000043 1.000000 0.361549 0.038148 0.000028 1.000000 0 0 0 0
0.900000 0.905000 0.910000 0.361549 0.038148 0.000028 1.000000 0.314651 0.022790 0.000017 1.000000 0 0 0 0
0.910000 0.915000 0.920000 0.314651 0.022790 0.000017 1.000000 0.267520 0.012778 0.000009 1.000000 0 0 0 0
0.920000 0.925000 0.930000 0.267520 0.012778 0.000009 1.000000 0.220535 0.006614 0.000005 1.000000 0 0 0 0
0.930000 0.935000 0.940000 0.220535 0.006614 0.000005 1.000000 0.174100 0.003084 0.000002 1.000000 0 0 0 0
0.940000 0.945000 0.950000 0.174100 0.003084 0.000002 1.000000 0.128659 0.001248 0.000001 1.000000 0 0 0 0
0.950000 0.955000 0.960000 0.128659 0.001248 0.000001 1.000000 0.084729 0.000411 0.000000 1.000000 0 0 0 0
0.960000 0.965000 0.970000 0.084729 0.000411 0.000000 1.000000 0.042944 0.000098 0.000000 1.000000 0 0 0 0
0.970000 0.975000 0.980000 0.042944 0.000098 0.000000 1.000000 0.012845 0.000013 0.000000 1.000000 0 0 0 0
0.980000 0.985000 0.990000 0.012845 0.000013 0.000000 1.000000 0.001613 0.000000 0.000000 1.000000 0 0 0 0
0.990000 0.995000 1.000000 0.001613 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0 0 0 0

0 comments on commit 71225b2

Please sign in to comment.