code wiki / (root) / nx_recycler_bench_fetch.nx

nx_recycler_bench_fetch.nx source

↩ module page · 51 lines · 3430 B

1// nx_recycler_bench_fetch.nx -- intake for the NISHI BENCHMARKING ENGINE: fetch real per-LANGUAGE / per-ECOSYSTEM 2// issue corpora so we can benchmark Nishi against C, Rust, JavaScript, Java, and Apache by THEIR known issues 3// (grounded -- each comparison cites a real fetched artifact, rule 4 / benchmarks-exist-separate). Wikipedia = the 4// allowed source. Saved to knowledge/fetched/recyc_lang_*.raw. Idempotent. expect_exit: 0 license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_x509_trust_store.nx" 7import "nx_trust_store_load_from_certdata.nx" 8import "nx_https_fetch_follow.nx" 9const K_MAGIC_4194304: i64 = 4194304 10const K_MAGIC_8388608: i64 = 8388608 11 12func gf_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func gf_putn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let d: *u8=sys_mmap(24); var k: i64=0; while m>0 { d[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var i: i64=k-1; while i>=0 { let o: *u8=sys_mmap(1); o[0]=d[i]; sys_write(1,o,1); i=i-1 } return 0 } 14func have_file(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } sys_close(fd); return 1 } 15 16func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 17 if have_file(opath)==1 { gf_puts(opath); gf_puts(" [have-skip]\n" as *u8); return 1 } 18 let status: *i64 = sys_mmap(8) as *i64 19 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 20 gf_puts(url); gf_puts(" status=" as *u8); gf_putn(status[0]); gf_puts(" bytes=" as *u8); gf_putn(n) 21 if n<=0 { gf_puts(" FETCH-FAIL\n" as *u8); return 0 } 22 var gz: i64=0 23 if n>=2 { if out[0]==0x1f as u8 { if out[1]==0x8b as u8 { gz=1 } } } 24 if gz==1 { gf_puts(" [GZIP-skip]\n" as *u8); return 0 } 25 let fd: i64=sys_openat_wr(opath, 0x1a4) 26 if fd<0 { gf_puts(" SAVE-FAIL\n" as *u8); return 0 } 27 sys_write(fd, out, n); sys_close(fd) 28 gf_puts(" SAVED\n" as *u8) 29 return 1 30} 31 32func main() -> i64 { 33 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 34 if r<=0 { gf_puts("BENCH: certdata load failed\n" as *u8); return 1 } 35 let store: *TrustStore = r as *TrustStore 36 gf_puts("CA roots=" as *u8); gf_putn(trust_store_count(store)); gf_puts("\n" as *u8) 37 let cap: i64 = K_MAGIC_8388608 38 let out: *u8 = sys_mmap(cap) 39 var ok: i64 = 0 40 41 gf_puts("== BENCHMARK INTAKE: language/ecosystem issue corpora (Nishi vs C/Rust/JS/Java/Apache) ==\n" as *u8) 42 ok = ok + fetch_save("https://en.wikipedia.org/wiki/C_(programming_language)" as *u8, "knowledge/fetched/recyc_lang_c.raw" as *u8, store, out, cap) 43 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rust_(programming_language)" as *u8, "knowledge/fetched/recyc_lang_rust.raw" as *u8, store, out, cap) 44 ok = ok + fetch_save("https://en.wikipedia.org/wiki/JavaScript" as *u8, "knowledge/fetched/recyc_lang_js.raw" as *u8, store, out, cap) 45 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Criticism_of_Java" as *u8, "knowledge/fetched/recyc_lang_java.raw" as *u8, store, out, cap) 46 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Apache_HTTP_Server" as *u8, "knowledge/fetched/recyc_lang_apache.raw" as *u8, store, out, cap) 47 48 gf_puts("BENCH-INTAKE sources_ok=" as *u8); gf_putn(ok); gf_puts("/5\n" as *u8) 49 if ok>=1 { return 0 } 50 return 1 51}