Skip to content

Instantly share code, notes, and snippets.

@haxney
Last active December 24, 2015 00:49
Show Gist options
  • Save haxney/6719953 to your computer and use it in GitHub Desktop.
Save haxney/6719953 to your computer and use it in GitHub Desktop.
Benchmark giving result of zero seconds.
extern mod cssparser;
extern mod extra;
extern mod servo_style;
use std::io::file_reader;
use std::cell::Cell;
use std::task;
use cssparser::*;
use extra::time::precise_time_ns;
fn bench(inner: &fn()) -> u64 {
let ns_start = precise_time_ns();
inner();
let ns_end = precise_time_ns();
return ns_end - ns_start;
}
fn bench_lex_one_file(path: Path) -> Result<u64, ()> {
let p = Cell::new(path);
do task::try {
let reader = file_reader(&p.take()).unwrap();
let css = reader.read_c_str();
do bench {
let mut a = parse_stylesheet_rules(tokenize(css));
for _ in a {}
}
}
}
fn bench_parse_one_file(path: Path) -> Result<u64, ()> {
let p = Cell::new(path);
do task::try {
let reader = file_reader(&p.take()).unwrap();
let css = reader.read_c_str();
do bench {
servo_style::stylesheets::parse_stylesheet(css);
}
}
}
fn main() {
let base_dir = &Path("sample-data");
let files = std::os::list_dir_path(base_dir);
println!("name,lex,parse");
for file in files.iter() {
let lex_time = bench_lex_one_file(file.clone());
let parse_time = bench_parse_one_file(file.clone());
match (lex_time, parse_time) {
(Ok(l), Ok(p)) =>
println!("{},{:.4f},{:.4f}",
file.filename().unwrap(),
l as float / 1_000f,
p as float / 1_000f),
_ => (),
}
}
}
| name | parse_pct | size |
|-------------------------+-----------+--------|
| youtube01.css | 4.8 | 293.04 |
| facebook04.css | 6.15 | 244.61 |
| twitter03.css | 7.65 | 161.32 |
| yahoo04.css | 4.45 | 154.4 |
| youtube02.css | 4.85 | 133.97 |
| bootstrap.css | 12.17 | 117.08 |
| wikipedia06.css | 18.29 | 116.46 |
| amazon14.css | 4.55 | 108.49 |
| bootstrap.min.css | 12.96 | 95.06 |
| facebook07.css | 4.76 | 77.38 |
| qq00.css | 9.5 | 68.29 |
| wikipedia02.css | 3.33 | 66.18 |
| facebook01.css | 4.2 | 52.32 |
| facebook03.css | 4.79 | 48.96 |
| google08.css | 4.29 | 45.02 |
| google00.css | 4.5 | 42 |
| facebook09.css | 9.92 | 40.71 |
| yahoo05.css | 9.3 | 40.11 |
| wikipedia01.css | 6.41 | 39.18 |
| facebook00.css | 7.03 | 33.78 |
| facebook08.css | 8.14 | 25.32 |
| wikipedia03.css | 11.43 | 25.08 |
| amazon13.css | 10.78 | 22.34 |
| amazon15.css | 14.06 | 21.88 |
| wikipedia07.css | 29.5 | 20.56 |
| bootstrap-theme.css | 2.18 | 16.42 |
| google03.css | 5.09 | 16.33 |
| bootstrap-theme.min.css | 2.23 | 14.64 |
| amazon00.css | 34.27 | 13.98 |
| amazon11.css | 6.8 | 8.53 |
| qq04.css | 4.93 | 8.4 |
| google07.css | 5.95 | 7.64 |
| wikipedia00.css | 8.42 | 7.21 |
| twitter00.css | 5.85 | 5.76 |
| youtube00.css | 14.99 | 4.76 |
| amazon16.css | 39.69 | 4.41 |
| baidu00.css | 16.53 | 3.25 |
| amazon09.css | 9.29 | 3.19 |
| google02.css | 11.97 | 3.05 |
| google01.css | 19.59 | 2.76 |
| qq05.css | 9.39 | 2.76 |
| google06.css | 10.08 | 2.53 |
| amazon03.css | 12.54 | 2.28 |
| amazon01.css | 24.41 | 2.09 |
| yahoo03.css | 16.28 | 1.96 |
| yahoo06.css | 15.48 | 1.81 |
| google05.css | 12.32 | 1.73 |
| amazon12.css | 14.91 | 1.32 |
| baidu01.css | 19.68 | 0.97 |
| amazon06.css | 24.58 | 0.95 |
| yahoo00.css | 23.8 | 0.95 |
| yahoo02.css | 21.64 | 0.74 |
| facebook02.css | 25.18 | 0.68 |
| facebook05.css | 25.95 | 0.57 |
| amazon10.css | 36.33 | 0.5 |
| amazon04.css | 35.72 | 0.49 |
| facebook06.css | 33.66 | 0.42 |
| google04.css | 29.64 | 0.41 |
| amazon02.css | 34.33 | 0.32 |
| qq01.css | 34.52 | 0.31 |
| amazon08.css | 60.88 | 0.27 |
| amazon05.css | 49.02 | 0.22 |
| qq02.css | 45.79 | 0.18 |
| wikipedia04.css | 59.86 | 0.18 |
| yahoo01.css | 48.22 | 0.18 |
| twitter01.css | 72.03 | 0.11 |
| amazon07.css | 60.42 | 0.11 |
| twitter02.css | 78.07 | 0.07 |
| wikipedia05.css | 78.68 | 0.07 |
| qq03.css | 81.38 | 0.03 |
name lex parse size
facebook00.css 20504.9120 22054.5990 34586
facebook01.css 30610.1200 31953.3390 53573
google02.css 1948.3620 2213.3990 3120
amazon11.css 4920.7390 5279.6030 8732
google03.css 10225.0570 10772.8640 16718
google04.css 309.8280 440.3200 423
google05.css 1052.1410 1199.9880 1768
google06.css 1795.2760 1996.6110 2590
google07.css 3311.8680 3521.4050 7822
google08.css 29837.3600 31174.3450 46104
facebook02.css 449.3090 600.4930 692
facebook03.css 30248.8150 31771.3210 50135
facebook04.css 147505.9680 157170.2960 250483
facebook05.css 403.2460 544.5490 588
facebook06.css 268.3480 404.5210 426
facebook07.css 47603.2350 49982.3770 79239
facebook08.css 15345.7130 16706.4150 25923
facebook09.css 26386.4270 29290.8070 41690
google00.css 28008.4590 29329.3960 43007
google01.css 1929.8030 2399.8080 2823
amazon00.css 9155.0110 13928.8850 14313
amazon01.css 1340.0240 1772.8660 2137
amazon02.css 236.3450 359.9220 323
amazon03.css 939.3430 1073.9820 2331
amazon04.css 335.7370 522.3260 504
amazon05.css 127.2330 249.5800 229
amazon06.css 397.1790 526.6390 972
amazon07.css 77.4270 195.6000 111
amazon08.css 140.5190 359.1560 277
amazon09.css 2072.1220 2284.3550 3265
amazon12.css 795.6140 935.0610 1353
amazon10.css 284.2570 446.4360 507
amazon13.css 13657.3470 15306.6670 22877
amazon14.css 64095.2780 67148.6950 111089
amazon15.css 14707.4930 17112.7390 22401
amazon16.css 2699.2020 4475.8750 4513
baidu01.css 617.5900 768.9320 995
baidu00.css 2204.6310 2641.3130 3330
qq00.css 45836.5480 50649.6320 69931
qq01.css 248.5830 379.6550 315
qq02.css 146.6700 270.5600 188
qq03.css 26.6710 143.2530 30
qq04.css 5511.0730 5796.7480 8598
twitter00.css 2996.3040 3182.5520 5903
qq05.css 1824.5080 2013.5720 2823
twitter01.css 56.6900 202.6510 113
twitter02.css 32.5510 148.4430 72
twitter03.css 97584.6050 105663.0070 165193
wikipedia00.css 4168.8570 4552.1370 7380
wikipedia01.css 16283.5700 17399.7450 40116
wikipedia02.css 28626.6600 29612.0440 67769
wikipedia03.css 13108.6830 14800.3630 25678
wikipedia04.css 82.5510 205.6730 187
wikipedia05.css 39.3270 184.4740 72
wikipedia06.css 49634.3460 60744.4550 119253
wikipedia07.css 12561.3940 17816.5910 21055
yahoo01.css 137.6800 265.8770 183
yahoo02.css 469.1690 598.7600 761
yahoo00.css 518.3100 680.1640 972
yahoo03.css 1208.0620 1442.9630 2012
yahoo04.css 94980.9440 99407.8420 158108
yahoo05.css 20380.0640 22468.6310 41073
yahoo06.css 829.2440 981.1270 1850
youtube00.css 3316.8480 3901.6520 4871
youtube01.css 170046.3710 178613.5420 300069
youtube02.css 76079.2810 79957.7900 137185
bootstrap.css 70109.7820 79826.2150 119892
bootstrap.min.css 58074.7720 66723.4080 97339
bootstrap-theme.css 10010.6000 10233.2180 16819
bootstrap-theme.min.css 8962.3200 9166.8360 14996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment