-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from flier/features/chimera
add chimera
- Loading branch information
Showing
99 changed files
with
8,860 additions
and
3,602 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,3 @@ | ||
.github | ||
examples | ||
*.tar.gz |
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
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 |
---|---|---|
|
@@ -25,3 +25,5 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
*.out |
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,61 @@ | ||
ARG UBUNTU_VERSION=20.04 | ||
|
||
FROM ubuntu:${UBUNTU_VERSION} | ||
|
||
ARG GO_VERSION=1.17.1 | ||
ARG HYPERSCAN_VERSION=5.4.0 | ||
ARG PCRE_VERSION=8.45 | ||
|
||
# Install dependencies | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
ca-certificates \ | ||
cmake \ | ||
libboost-dev \ | ||
libbz2-dev \ | ||
libpcap-dev \ | ||
ninja-build \ | ||
pkg-config \ | ||
python2.7 \ | ||
ragel \ | ||
wget \ | ||
zlib1g-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install golang | ||
|
||
RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz -O /go${GO_VERSION}.tar.gz && \ | ||
rm -rf /usr/local/go && \ | ||
tar -C /usr/local -xzf /go${GO_VERSION}.tar.gz && \ | ||
rm /go${GO_VERSION}.tar.gz | ||
|
||
ENV PATH=/usr/local/go/bin:${PATH} | ||
|
||
# Download Hyperscan | ||
|
||
ENV HYPERSCAN_DIR=/hyperscan | ||
|
||
RUN wget https://github.com/intel/hyperscan/archive/refs/tags/v${HYPERSCAN_VERSION}.tar.gz -O /hyperscan-${HYPERSCAN_VERSION}.tar.gz && \ | ||
mkdir ${HYPERSCAN_DIR} && tar xf /hyperscan-${HYPERSCAN_VERSION}.tar.gz -C ${HYPERSCAN_DIR} --strip-components=1 && rm /hyperscan-${HYPERSCAN_VERSION}.tar.gz | ||
RUN wget https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz/download -O /pcre-${PCRE_VERSION}.tar.gz && \ | ||
mkdir ${HYPERSCAN_DIR}/pcre && tar xf /pcre-${PCRE_VERSION}.tar.gz -C ${HYPERSCAN_DIR}/pcre --strip-components=1 && rm /pcre-${PCRE_VERSION}.tar.gz | ||
|
||
# Install Hyperscan | ||
|
||
ENV INSTALL_DIR=/usr/local | ||
|
||
RUN mkdir ${HYPERSCAN_DIR}/build && cd ${HYPERSCAN_DIR}/build && \ | ||
cmake -G Ninja -DBUILD_STATIC_LIBS=on -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} ${HYPERSCAN_DIR} && \ | ||
ninja && ninja install && mv ${HYPERSCAN_DIR}/build/lib/lib*.a ${INSTALL_DIR}/lib/ && cd / && rm -rf ${HYPERSCAN_DIR} | ||
|
||
ENV PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig | ||
|
||
# Add gohs code | ||
|
||
ADD . /gohs/ | ||
|
||
WORKDIR /gohs | ||
ENTRYPOINT ["/usr/local/go/bin/go"] | ||
CMD ["test", "./..."] |
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
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,49 @@ | ||
//go:build chimera | ||
// +build chimera | ||
|
||
package scan_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/flier/gohs/chimera" | ||
) | ||
|
||
func BenchmarkChimeraBlockScan(b *testing.B) { | ||
isRaceBuilder := strings.HasSuffix(testenv(), "-race") | ||
|
||
for _, data := range benchData { | ||
p := chimera.NewPattern(data.re, chimera.MultiLine) | ||
db, err := chimera.NewBlockDatabase(p) | ||
if err != nil { | ||
b.Fatalf("compile pattern %s: `%s`, %s", data.name, data.re, err) | ||
} | ||
|
||
s, err := chimera.NewScratch(db) | ||
if err != nil { | ||
b.Fatalf("create scratch, %s", err) | ||
} | ||
|
||
m := chimera.HandlerFunc(func(id uint, from, to uint64, flags uint, | ||
captured []*chimera.Capture, context interface{}, | ||
) chimera.Callback { | ||
return chimera.Terminate | ||
}) | ||
|
||
for _, size := range benchSizes { | ||
if (isRaceBuilder || testing.Short()) && size.n > 1<<10 { | ||
continue | ||
} | ||
t := makeText(size.n) | ||
b.Run(data.name+"/"+size.name, func(b *testing.B) { | ||
b.SetBytes(int64(len(t))) | ||
for i := 0; i < b.N; i++ { | ||
if err = db.Scan(t, s, m, nil); err != nil { | ||
b.Fatalf("match, %s", err) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.