edge-bench-rs: upload tools, release-name checks and common Date headers by hand

Each with its regex/chrono version as the reference in tests; check.ts
still finds all three captures identical. Boneless 2026 ~500k headers/s,
ath 2013 ~650k.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-09 09:31:56 +02:00
1 parent 43e74199d4
commit b1c2db5984
2 files changed
+221 -5

No files matched your search

+138 -5
View File
@@ -318,11 +318,12 @@ pub fn is_post_token(remainder: &str) -> bool {
(6..=40).contains(&n) && compact.bytes().any(|b| b.is_ascii_digit()) && compact.bytes().all(|b| b.is_ascii_alphanumeric())
}
#[allow(dead_code)]
static NAME_LIKE: LazyLock<Regex> = LazyLock::new(|| re(r"[A-Za-z]{2,}[._ -]+[A-Za-z0-9]{2,}"));
pub fn names_release(remainder: &str) -> bool {
let words: Vec<&str> = js::split_spaces(remainder).into_iter().filter(|w| !w.is_empty() && !is_random_token(w)).collect();
test(&NAME_LIKE, &words.join(" "))
name_like(words.join(" ").as_bytes())
}
#[derive(Debug, Clone)]
@@ -340,6 +341,7 @@ impl Release {
}
}
#[allow(dead_code)]
static FILE_COUNTER: LazyLock<Regex> = LazyLock::new(|| re(r"\[([0-9]+)/([0-9]+)\]"));
fn hash(parts: &[&str]) -> String {
@@ -348,9 +350,7 @@ fn hash(parts: &[&str]) -> String {
/// releaseIdentity for a named (not weak) file: never null.
pub fn release_identity(poster: &str, subject: &str, name: &str) -> Release {
let file_total = FILE_COUNTER
.captures(subject.as_bytes())
.and_then(|c| js::parse_int(std::str::from_utf8(&c[2]).unwrap()));
let file_total = file_counter_total(subject);
let stem = file_stem(name);
let remainder = subject_remainder(subject);
if names_release(&remainder) {
@@ -480,7 +480,9 @@ static TOOLS: LazyLock<Vec<(&'static str, Regex)>> = LazyLock::new(|| {
]
});
pub fn upload_tool(message_id: &str) -> &'static str {
/// uploadTool with the regexes, as in the TypeScript (the reference for upload_tool's test).
#[allow(dead_code)]
pub fn upload_tool_re(message_id: &str) -> &'static str {
if message_id.is_empty() {
return "other";
}
@@ -492,6 +494,116 @@ pub fn upload_tool(message_id: &str) -> &'static str {
"other"
}
fn all(s: &[u8], f: impl Fn(u8) -> bool) -> bool {
s.iter().all(|&c| f(c))
}
fn lower_hex(c: u8) -> bool {
c.is_ascii_digit() || (b'a'..=b'f').contains(&c)
}
/// `(?:[A-Z][a-z]){12}-\d{13}@`: nyuu's prefix (38 bytes, then '@').
fn nyuu_prefix(b: &[u8]) -> bool {
b.len() > 38 && (0..24).step_by(2).all(|i| b[i].is_ascii_uppercase() && b[i + 1].is_ascii_lowercase()) && b[24] == b'-' && all(&b[25..38], |c| c.is_ascii_digit()) && b[38] == b'@'
}
/// The posting tool of a Message-ID (TOOLS, in order, by hand: they ran for every per-article file).
pub fn upload_tool(message_id: &str) -> &'static str {
let b = message_id.as_bytes();
if b.is_empty() {
return "other";
}
if nyuu_prefix(b) && b.len() > 39 {
// nyuu: "@nyuu" exactly; nyuu-host: any host (`.+`: no line terminators).
if &b[39..] == b"nyuu" {
return "nyuu";
}
if !b[39..].iter().any(|&c| c == b'\n' || c == b'\r') && !message_id[39..].contains(['\u{2028}', '\u{2029}']) {
return "nyuu-host";
}
}
let hex32 = b.len() > 33 && all(&b[..32], lower_hex) && b[32] == b'@';
if hex32 {
let host = &b[33..];
if host == b"ngPost" {
return "ngPost";
}
if host.len() == 37 && all(&host[..32], lower_hex) && &host[32..] == b".yuun" {
return "yuun";
}
if all(host, |c| c.is_ascii_alphanumeric() || c == b'.' || c == b'-') {
return "hex32";
}
}
if message_id.ends_with("@JBinUp.local") || message_id.ends_with("@JBinDown.local") {
return "JBinUp";
}
// (?i)^part\d+of\d+\.
if b.len() > 4 && eq_ci(&b[..4], b"part") {
let d1 = b[4..].iter().take_while(|c| c.is_ascii_digit()).count();
let of = 4 + d1;
if d1 > 0 && b.len() > of + 2 && eq_ci(&b[of..of + 2], b"of") {
let d2 = b[of + 2..].iter().take_while(|c| c.is_ascii_digit()).count();
if d2 > 0 && b.get(of + 2 + d2) == Some(&b'.') {
return "partNofM";
}
}
}
// ^\d{13}\$\d+\$\d+@localhost$
if let Some(rest) = message_id.strip_suffix("@localhost") {
let r = rest.as_bytes();
let parts: Vec<&[u8]> = r.split(|&c| c == b'$').collect();
if parts.len() == 3 && parts[0].len() == 13 && parts.iter().all(|p| !p.is_empty() && all(p, |c| c.is_ascii_digit())) {
return "ts-dollar";
}
}
// ^[A-Za-z0-9]{10,40}@[A-Za-z0-9]{3,12}\.[A-Za-z0-9]{2,6}$
if let Some(at) = b.iter().position(|&c| c == b'@') {
let (local, host) = (&b[..at], &b[at + 1..]);
if (10..=40).contains(&local.len()) && all(local, |c| c.is_ascii_alphanumeric()) {
if let Some(dot) = host.iter().position(|&c| c == b'.') {
let (name, tld) = (&host[..dot], &host[dot + 1..]);
if (3..=12).contains(&name.len()) && (2..=6).contains(&tld.len()) && all(name, |c| c.is_ascii_alphanumeric()) && all(tld, |c| c.is_ascii_alphanumeric()) {
return "random";
}
}
}
}
"other"
}
/// [A-Za-z]{2,}[._ -]+[A-Za-z0-9]{2,} anywhere.
fn name_like(b: &[u8]) -> bool {
let sep = |c: u8| matches!(c, b'.' | b'_' | b' ' | b'-');
(2..b.len()).any(|k| {
if !(sep(b[k]) && b[k - 1].is_ascii_alphabetic() && b[k - 2].is_ascii_alphabetic()) {
return false;
}
let m = k + b[k..].iter().take_while(|&&c| sep(c)).count();
m + 2 <= b.len() && b[m].is_ascii_alphanumeric() && b[m + 1].is_ascii_alphanumeric()
})
}
/// The second number of the first \[(\d+)/(\d+)\].
fn file_counter_total(s: &str) -> Option<i64> {
let b = s.as_bytes();
for (i, &c) in b.iter().enumerate() {
if c != b'[' {
continue;
}
let a = b[i + 1..].iter().take_while(|c| c.is_ascii_digit()).count();
let slash = i + 1 + a;
if a == 0 || b.get(slash) != Some(&b'/') {
continue;
}
let d = b[slash + 1..].iter().take_while(|c| c.is_ascii_digit()).count();
if d > 0 && b.get(slash + 1 + d) == Some(&b']') {
return js::parse_int(&s[slash + 1..slash + 1 + d]);
}
}
None
}
/// explored: a release in the sampled share of a rule's drops.
pub fn explored(key: &str, percent: f64) -> bool {
if percent <= 0.0 {
@@ -589,6 +701,27 @@ mod tests {
}
}
#[test]
fn tools_by_hand_as_the_regexes() {
let ids = [
"FmFwIaTpGgUiSfYcMwFlMeRo-1790637260478@nyuu", "FmFwIaTpGgUiSfYcMwFlMeRo-1790637260478@", "FmFwIaTpGgUiSfYcMwFlMeRo-1790637260478@news.example",
"b94268bc702040f7b811d5318f727e4f@ngPost", "b94268bc702040f7b811d5318f727e4f@b94268bc702040f7b811d5318f727e4f.yuun", "b94268bc702040f7b811d5318f727e4f@host-1.example",
"B94268bc702040f7b811d5318f727e4f@ngPost", "x@JBinUp.local", "y@JBinDown.local", "part1of69.lOlWzvSHabJCBTVrs0ts@AdultPoster.local", "PART12OF3.x",
"1790923856877$1729905757859$1@localhost", "179092385687$1$1@localhost", "t3Y4mV92YCp0McxDc5@zLZlsw.RYqes", "t3Y4mV92YC@zL.RYqes", "t3Y4mV92YCp0McxDc5@zLZlsw.RY.es",
"", "a@b", "b94268bc702040f7b811d5318f727e4f@", "b94268bc702040f7b811d5318f727e4f@host_x",
];
for id in ids {
assert_eq!(upload_tool(id), upload_tool_re(id), "{id}");
}
for t in ["Some Release", "a b", "ab-cd", "ab - c1", "ab.c", "x ab_12", "12 ab", "ab "] {
assert_eq!(name_like(t.as_bytes()), test(&NAME_LIKE, t), "{t}");
}
for t in ["[01/45] x", "x [1/] [2/30]", "[a/1] [3/4]", "no counter"] {
let re = FILE_COUNTER.captures(t.as_bytes()).and_then(|c| js::parse_int(std::str::from_utf8(&c[2]).unwrap()));
assert_eq!(file_counter_total(t), re, "{t}");
}
}
#[test]
fn random_names() {
assert!(looks_random("prvjr7hapd0i1ny14pz4"));