-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicode and DNA regexes + more benchmarker improvements #515
base: main
Are you sure you want to change the base?
Changes from 4 commits
e518bdf
eb64036
1237f9a
fdf2c23
0a1a32a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import _StringProcessing | ||
|
||
extension BenchmarkRunner { | ||
mutating func addDna() { | ||
// regex-redux from the benchmarks game | ||
// https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/regexredux.html#regexredux | ||
let dna = "agg[act]taaa|ttta[agt]cct" | ||
let ends = "aND|caN|Ha[DS]|WaS" | ||
|
||
let dnaMatching = CrossBenchmark( | ||
baseName: "DnaMatch", | ||
regex: dna, | ||
input: Inputs.dnaFASTA, | ||
includeFirst: true) | ||
|
||
let sequenceEnds = CrossBenchmark( | ||
baseName: "DnaEndsMatch", | ||
regex: ends, | ||
input: Inputs.dnaFASTA, | ||
includeFirst: true) | ||
|
||
dnaMatching.register(&self) | ||
sequenceEnds.register(&self) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import _StringProcessing | ||
|
||
extension BenchmarkRunner { | ||
mutating func addUnicode() { | ||
// tagged unicode: unicode characters surrounded by html tags | ||
// use the same html regex, uses backreference + reluctant quantification | ||
let tags = #"<(\w*)\b[^>]*>(.*?)<\/\1>"# | ||
let taggedEmojis = CrossBenchmark( | ||
baseName: "TaggedEmojis", | ||
regex: tags, | ||
input: Inputs.taggedEmojis) | ||
|
||
// Now actually matching emojis | ||
let emoji = #"(😃|😀|😳|😲|😦|😊|🙊|😘|😏|😳|😒){2,5}"# | ||
|
||
let emojiRegex = CrossBenchmark( | ||
baseName: "EmojiRegex", | ||
regex: emoji, | ||
input: Inputs.taggedEmojis) | ||
|
||
taggedEmojis.register(&self) | ||
emojiRegex.register(&self) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# DnaFasta.swift was generated with python3 Utils/generateFasta.py 100000 | ||
|
||
# The Computer Language Benchmarks Game | ||
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/ | ||
# | ||
# modified by Ian Osgood | ||
# modified again by Heinrich Acker | ||
# modified by Justin Peel | ||
# 2to3 | ||
|
||
"""Copyright © 2004-2008 Brent Fulgham, 2005-2022 Isaac Gouy | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name "The Computer Language Benchmarks Game" nor the name "The Benchmarks Game" nor the name "The Computer Language Shootout Benchmarks" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stephentyrone Can you check off on licensing here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took the script from here https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/fasta-python3-1.html and copied over the license from the repo here https://salsa.debian.org/benchmarksgame-team/benchmarksgame/-/blob/master/LICENSE.md Not sure if the "redistributions of source code" applies only to the code in the repo for the website/benchmarking harness or for the scripts that users submit as well |
||
|
||
import sys, bisect | ||
|
||
alu = ( | ||
'GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG' | ||
'GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA' | ||
'CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT' | ||
'ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA' | ||
'GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG' | ||
'AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC' | ||
'AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA') | ||
|
||
iub = list(zip('acgtBDHKMNRSVWY', [0.27, 0.12, 0.12, 0.27] + [0.02]*11)) | ||
|
||
homosapiens = [ | ||
('a', 0.3029549426680), | ||
('c', 0.1979883004921), | ||
('g', 0.1975473066391), | ||
('t', 0.3015094502008), | ||
] | ||
|
||
|
||
def genRandom(ia = 3877, ic = 29573, im = 139968): | ||
seed = 42 | ||
imf = float(im) | ||
while 1: | ||
seed = (seed * ia + ic) % im | ||
yield seed / imf | ||
|
||
Random = genRandom() | ||
|
||
def makeCumulative(table): | ||
P = [] | ||
C = [] | ||
prob = 0. | ||
for char, p in table: | ||
prob += p | ||
P += [prob] | ||
C += [char] | ||
return (P, C) | ||
|
||
def repeatFasta(src, n): | ||
width = 60 | ||
r = len(src) | ||
s = src + src + src[:n % r] | ||
for j in range(n // width): | ||
i = j*width % r | ||
print(s[i:i+width]) | ||
if n % width: | ||
print(s[-(n % width):]) | ||
|
||
def randomFasta(table, n): | ||
width = 60 | ||
r = range(width) | ||
gR = Random.__next__ | ||
bb = bisect.bisect | ||
jn = ''.join | ||
probs, chars = makeCumulative(table) | ||
for j in range(n // width): | ||
x = jn([chars[bb(probs, gR())] for i in r]) | ||
print(x) | ||
if n % width: | ||
print(jn([chars[bb(probs, gR())] for i in range(n % width)])) | ||
|
||
def main(): | ||
n = int(sys.argv[1]) | ||
|
||
print('>ONE Homo sapiens alu') | ||
repeatFasta(alu, n*2) | ||
|
||
print('>TWO IUB ambiguity codes') | ||
randomFasta(iub, n*3) | ||
|
||
print('>THREE Homo sapiens frequency') | ||
randomFasta(homosapiens, n*5) | ||
|
||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I believe Swift's naming convention would prefer to keep them all capitalized or all lower case. Not a big deal to me.