///|
fn parse_iterations(text : String) -> Int {
let mut value = 0
for ch in text {
if ch < '0' || ch > '9' {
return 10000
}
value = value * 10 + ch.to_int() - '0'.to_int()
}
if value <= 0 {
10000
} else {
value
}
}
///|
fn read_file(path : String) -> String? {
Some(@fs.read_file_to_string(path)) catch {
_ => None
}
}
///|
fn main {
let args = @env.args()
if args.length() < 3 {
println("Usage: moonspell-bench [iterations]")
return
}
let iterations = if args.length() >= 4 {
parse_iterations(args[3])
} else {
10000
}
let aff = match read_file(args[1]) {
Some(value) => value
None => {
println("failed to read affix file")
return
}
}
let dic = match read_file(args[2]) {
Some(value) => value
None => {
println("failed to read dictionary file")
return
}
}
let load_start = @env.now()
let config = @lib.parse_aff(aff).unwrap()
let dictionary = @lib.parse_dic(dic).unwrap()
let load_end = @env.now()
if dictionary.entries.length() == 0 {
println("empty dictionary")
return
}
let exact_start = @env.now()
let mut accepted = 0
for i in 0.. 10000 {
0
} else if iterations < 10 {
iterations
} else {
10
}
for i in 0..