-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native support for regex benchmark (#266)
* Add native support for regex benchmark * Remove comments in Dockerfile.native for regex
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/rust-benchmark-native/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM rust:1.70 | ||
|
||
# Copy in the `src` directory. | ||
ENV SRC=/usr/src/regex/ | ||
WORKDIR $SRC | ||
ADD rust-benchmark rust-benchmark | ||
COPY sightglass.native.patch ./ | ||
COPY build-native.sh . | ||
COPY libengine.so /usr/lib/ | ||
|
||
# Compile each of the benchmarks into the `/benchmark` directory. | ||
RUN ./build-native.sh | ||
|
||
# We copy the shared libraries to the `/benchmark` directory, where the client | ||
# expects it. | ||
WORKDIR /benchmark | ||
RUN cp $SRC/*so . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Build regex benchmark as native shared libraries (Linux-only). | ||
# | ||
# Usage: ./build-native.sh | ||
|
||
(set -x;) | ||
(rm -rf rust-benchmark-native); | ||
(cp -r rust-benchmark rust-benchmark-native/); | ||
(cp sightglass.native.patch rust-benchmark-native/); | ||
(cd rust-benchmark-native; patch -Np1 -i ./sightglass.native.patch; cd -); | ||
(cd rust-benchmark-native; cargo build --release; cp target/release/libbenchmark.so ../benchmark.so; cd -); | ||
(set +x;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
diff --git a/Cargo.toml b/Cargo.toml | ||
index ee59a1c..dbeccb7 100644 | ||
--- a/Cargo.toml | ||
+++ b/Cargo.toml | ||
@@ -8,3 +8,6 @@ regex = "1.7.1" | ||
sightglass-api = "0.1" | ||
|
||
[workspace] | ||
+ | ||
+[lib] | ||
+crate-type = ["cdylib"] | ||
\ No newline at end of file | ||
diff --git a/build.rs b/build.rs | ||
new file mode 100644 | ||
index 0000000..6d7d743 | ||
--- /dev/null | ||
+++ b/build.rs | ||
@@ -0,0 +1,3 @@ | ||
+fn main() { | ||
+ println!("cargo:rustc-cdylib-link-arg=-L../../../engines/native/"); | ||
+} | ||
diff --git a/src/main.rs b/src/lib.rs | ||
similarity index 84% | ||
rename from src/main.rs | ||
rename to src/lib.rs | ||
index a1ef2f8..0bf007d 100644 | ||
--- a/src/main.rs | ||
+++ b/src/lib.rs | ||
@@ -13,16 +13,27 @@ const URI_PATTERN: &str = r"[\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?" | ||
const IP_PATTERN: &str = | ||
r"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])"; | ||
|
||
-fn main() { | ||
+#[link(name = "engine")] | ||
+extern "C" { | ||
+ fn bench_start() -> (); | ||
+ fn bench_end() -> (); | ||
+} | ||
+ | ||
+#[no_mangle] | ||
+pub extern "C" fn native_entry() { | ||
let path = "default.input"; | ||
eprintln!("[regex] matching {}", path); | ||
let data = std::fs::read_to_string(path).expect("unable to find `*.input` text file"); | ||
|
||
- bench::start(); | ||
+ unsafe { | ||
+ bench_start(); | ||
+ } | ||
let emails = count_matches(&data, EMAIL_PATTERN); | ||
let uris = count_matches(&data, URI_PATTERN); | ||
let ips = count_matches(&data, IP_PATTERN); | ||
- bench::end(); | ||
+ unsafe { | ||
+ bench_end(); | ||
+ } | ||
|
||
eprintln!("[regex] found {} emails", emails); | ||
eprintln!("[regex] found {} URIs", uris); |