Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ script:
- if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
travis_wait ./run-bench rust;
travis_wait ./run-bench rust-bytes --no-run;
travis_wait ./run-bench rust-plugin --no-run;
travis_wait ./run-bench pcre --no-run;
travis_wait ./run-bench pcre1 --no-run;
travis_wait ./run-bench onig --no-run;
travis_wait cargo test --verbose --manifest-path=regex_macros/Cargo.toml;
fi
Expand Down
62 changes: 23 additions & 39 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,58 @@ repository = "https://github.com/rust-lang/regex"
documentation = "http://doc.rust-lang.org/regex/regex_syntax/index.html"
homepage = "https://github.com/rust-lang/regex"
description = "Regex benchmarks for Rust's and other engines."

build = "build.rs"

[dependencies]
docopt = "0.6"
lazy_static = "0.1"
libc = "0.2"
onig = { version = "0.4", optional = true }
libpcre-sys = { version = "0.2", optional = true }
memmap = "0.2"
regex = { version = "0.1", path = ".." }
regex_macros = { version = "0.1", path = "../regex_macros", optional = true }
regex-syntax = { version = "0.3", path = "../regex-syntax" }
rustc-serialize = "0.3"

[build-dependencies]
gcc = "0.3"
pkg-config = "0.3"

[[bin]]
name = "regex-run-one"
path = "src/main.rs"
bench = false

# Use features to conditionally compile benchmarked regexes, since not every
# regex works on every engine. Additionally, it is useful to be able to build
# each benchmark individually, so that not all dependencies are required to
# run only one benchmark.
#
# Note that when running benchmarks, only ONE feature should be set at a time.
# Doing anything else will probably result in weird "duplicate definition"
# compiler errors.
#
# Tip: use the run-bench script in the root of this repository to run
# benchmarks.
[features]
re-pcre = ["libpcre-sys"]
re-pcre1 = ["libpcre-sys"]
re-pcre2 = []
re-onig = ["onig"]
re-re2 = []
re-rust = []
re-rust-bytes = []
re-rust-plugin = ["regex_macros"]
re-tcl = []

# Run the benchmarks on the default behavior of Regex::new.
[[bench]]
name = "rust"
path = "src/bench_rust.rs"
test = false
bench = true

# Run the benchmarks on the default behavior of bytes::Regex::new.
[[bench]]
name = "rust-bytes"
path = "src/bench_rust_bytes.rs"
test = false
bench = true

# Run the benchmarks on the default behavior of the `regex!` compiler plugin.
[[bench]]
name = "rust-plugin"
path = "src/bench_rust_plugin.rs"
test = false
bench = true

# Run the benchmarks on PCRE.
[[bench]]
name = "pcre"
path = "src/bench_pcre.rs"
name = "bench"
path = "src/bench.rs"
test = false
bench = true

# Run the benchmarks on PCRE2.
[[bench]]
name = "pcre2"
path = "src/bench_pcre2.rs"
test = false
bench = true

# Run the benchmarks on Oniguruma.
[[bench]]
name = "onig"
path = "src/bench_onig.rs"
test = false
bench = true
[profile.release]
debug = true

[profile.bench]
debug = true
Expand Down
33 changes: 29 additions & 4 deletions benches/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate gcc;
extern crate pkg_config;

use std::env;
use std::process;

use pkg_config::Config;

macro_rules! we {
($($tt:tt)*) => {{
use std::io::Write;
Expand All @@ -23,11 +22,37 @@ macro_rules! we {
}

fn main() {
// We only need to look for PCRE2 and RE2 because we roll the FFI bindings
// for those libraries ourselves from scratch. For PCRE1 and Oniguruma, we
// rely on other crates that do something similar to the dance below for
// us.

let wants_pcre2 = env::var("CARGO_FEATURE_RE_PCRE2").is_ok();
let has_pcre2 =
Config::new().atleast_version("10.21").find("libpcre2-8").is_ok();
let has_pcre2 = pkg_config::Config::new().find("libpcre2-8").is_ok();
if wants_pcre2 && !has_pcre2 {
we!("pcre2 cannot be found by pkg-config");
process::exit(1);
}

let wants_re2 = env::var("CARGO_FEATURE_RE_RE2").is_ok();
let has_re2 = pkg_config::Config::new().find("re2").is_ok();
if wants_re2 {
if !has_re2 {
we!("re2 cannot be found by pkg-config");
process::exit(1);
}
gcc::Config::new()
.cpp(true)
.flag("-std=c++11")
.file("src/ffi/re2.cpp")
.compile("libcre2.a");
println!("cargo:rustc-link-lib=re2");
}

let wants_tcl = env::var("CARGO_FEATURE_RE_TCL").is_ok();
let has_tcl = pkg_config::Config::new().find("tcl").is_ok();
if wants_tcl && !has_tcl {
we!("tcl cannot be found by pkg-config");
process::exit(1);
}
}
6 changes: 6 additions & 0 deletions benches/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

exec cargo build \
--release \
--features 're-onig re-pcre1 re-pcre2 re-re2 re-rust re-rust-bytes re-tcl' \
"$@"
1 change: 1 addition & 0 deletions benches/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
42 changes: 42 additions & 0 deletions benches/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

usage() {
echo "Usage: $(basename $0) [rust | rust-bytes | rust-plugin | pcre1 | pcre2 | re2 | onig | tcl ]" >&2
exit 1
}

if [ $# = 0 ] || [ $1 = '-h' ] || [ $1 = '--help' ]; then
usage
fi

which="$1"
shift
case $which in
rust)
exec cargo bench --bench bench --features re-rust "$@"
;;
rust-bytes)
exec cargo bench --bench bench --features re-rust-bytes "$@"
;;
rust-plugin)
exec cargo bench --bench bench --features re-rust-plugin "$@"
;;
re2)
exec cargo bench --bench bench --features re-re2 "$@"
;;
pcre1)
exec cargo bench --bench bench --features re-pcre1 "$@"
;;
pcre2)
exec cargo bench --bench bench --features re-pcre2 "$@"
;;
onig)
exec cargo bench --bench bench --features re-onig "$@"
;;
tcl)
exec cargo bench --bench bench --features re-tcl "$@"
;;
*)
usage
;;
esac
Loading