Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/mailhand/blob/main/tests/bench-lib.om # mailhand mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `mailhand / tests / bench-lib.om` 938 lines ยท 20065 bytes Raw Blame History 1 note ======== tests/bench-lib.om: synthetic Maildir generator and exact rate printing (GateBuilder) ======== 2 note Shared by tests/gen/mkmaildir.om and tests/bench.om; listed after src/core.om and src/sha.om in 3 note tests/units/mkmaildir.txt and tests/BENCH_UNITS. Uses core paths (gp, p_*), store S_AUX (the 4 note Maildir root path) and core output (o_b, o_raw, o_digits, o_flush to stdout with gv VMODE 0). 5 note 6 note Maildir written by mk_gen N SEED (root = the path held in store S_AUX): 7 note ROOT/cur ROOT/new ROOT/tmp (mode 0700 before umask; ROOT must not exist, its parent must). 8 note Message i (0..N-1): file ROOT/new/T.MiPSEED.example when i rem 3 is 0 (unread), else 9 note ROOT/cur/T.MiPSEED.example:2,S (seen) (i and SEED in decimal); mode 0644 before umask; LF line 10 note ends, no CR. 11 note T = `1735689600` (2025-01-01T00:00:00Z) + 600 i + (mix(SMIX + 2i + 1) rem 600), so T grows with i. 12 note Kind i rem 5: 0 plain (no MIME headers), 1 multipart/mixed: text/plain part + base64 13 note application/octet-stream attachment of 64..16447 random bytes (76-character lines), 2 text/plain 14 note utf-8 quoted-printable body with UTF-8 letters and "=" escaped and soft breaks (lines <= 76), 15 note 3 RFC 2047 encoded words: Subject B- or Q-encoded (UTF-8 letter at the end), From display name 16 note Q-encoded, 4 thread reply: "Re: " + the subject of an earlier message j (0 <= j < i), 17 note In-Reply-To and References . 18 note Every message: Date (matches T, UTC), From "Name Name ", 19 note To "Bench Reader ", Cc one example.org address in about 1 of 4, 20 note Subject, Message-ID . Only example.org addresses appear. 21 note Contents come only from SEED and i (splitmix64: SMIX = mix(SEED + 0x9e3779b97f4a7c15), 22 note message i body stream state mix(SMIX + 2i + 1), subject stream of message j mix(SMIX + 2j)), so 23 note the same N and SEED give byte-identical files; the first N of a larger N are the same files. 24 note No array grows with the output: bytes go through the 64 KiB window mk_w to the open file; a 25 note message has no size limit. Fixed local arrays below hold generator-chosen words (at most 9 26 note letters) and subjects (at most 53 bytes), never input. Files are not fsynced (bench data). 27 28 const MK_WIN ulong 65536 29 const MK_FMODE int 420 30 note mk_g cells: 0 random state, 1 bytes waiting in mk_w, 2 descriptor+1, 3 failed (1), 4 errno, 31 note 5 bytes of the current file, 6 total bytes, 7 seed, 8 column (base64/QP), 9 base64 group, 32 note 10 bytes in the group, 11 files in new, 12 files in cur, 13..17 messages of kind 0..4, 33 note 18 SMIX, 19 epoch of the current message, 20 N, 30 bad argument (mk_argnum) 34 const MKG_RNG ulong 0 35 const MKG_WN ulong 1 36 const MKG_FD ulong 2 37 const MKG_FAIL ulong 3 38 const MKG_ERRNO ulong 4 39 const MKG_FB ulong 5 40 const MKG_TB ulong 6 41 const MKG_SEED ulong 7 42 const MKG_COL ulong 8 43 const MKG_ACC ulong 9 44 const MKG_NACC ulong 10 45 const MKG_NEW ulong 11 46 const MKG_CUR ulong 12 47 const MKG_KIND ulong 13 48 const MKG_SMIX ulong 18 49 const MKG_T ulong 19 50 const MKG_N ulong 20 51 const MKG_BAD ulong 30 52 global mk_w uchar 65536 53 global mk_g ulong 32 54 55 text mkt_cons "bcdfghjklmnprstvwz" 56 text mkt_vow "aeiou" 57 text mkt_b64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 58 text mkt_hexu "0123456789ABCDEF" 59 text mkt_wd "SunMonTueWedThuFriSat" 60 text mkt_mon "JanFebMarAprMayJunJulAugSepOctNovDec" 61 text mkt_nl "\n" 62 text mkt_hdate "Date: " 63 text mkt_comsp ", " 64 text mkt_utc " +0000\n" 65 text mkt_hfrom "From: " 66 text mkt_lt " <" 67 text mkt_atgt "@example.org>\n" 68 text mkt_hto "To: Bench Reader \n" 69 text mkt_hcc "Cc: " 70 text mkt_atnl "@example.org\n" 71 text mkt_hsubj "Subject: " 72 text mkt_re "Re: " 73 text mkt_ewb "=?UTF-8?B?" 74 text mkt_ewq "=?UTF-8?Q?" 75 text mkt_ewe "?=" 76 text mkt_hmid "Message-ID: 0) 131 fn mk_rn n ulong to ulong 132 ret rem mk_rnd n 133 end 134 135 note ---- output window ---- 136 note mk_fail: remember the first failure; r is the host word result (-errno, or 0 for no progress) 137 fn mk_fail r long to void 138 if ne get mk_g MKG_FAIL 0 139 ret 140 end 141 e = long 5 142 if lt r 0 143 e = neg r 144 end 145 put mk_g MKG_FAIL 1 146 put mk_g MKG_ERRNO ulong e 147 end 148 149 note mk_flush: write the waiting bytes of mk_w to the current file; false after any failure (sticky) 150 fn mk_flush to bool 151 if ne get mk_g MKG_FAIL 0 152 ret false 153 end 154 n = get mk_g MKG_WN 155 fd = int sub get mk_g MKG_FD 1 156 p = ulong 0 157 while lt p n bound `9223372036854775807` 158 r = write fd mk_w p sub n p 159 if eq r -4 160 continue 161 end 162 if le r 0 163 mk_fail r 164 ret false 165 end 166 p = add p ulong r 167 end 168 put mk_g MKG_WN 0 169 ret true 170 end 171 172 fn mk_b c uchar to void 173 n = get mk_g MKG_WN 174 if ge n MK_WIN 175 z = mk_flush 176 put mk_g MKG_WN 0 177 n = ulong 0 178 end 179 put mk_w n c 180 put mk_g MKG_WN add n 1 181 put mk_g MKG_FB add get mk_g MKG_FB 1 182 end 183 184 fn mk_t t view uchar * to void 185 for i ulong len t bound `9223372036854775807` 186 mk_b get t i 187 end 188 end 189 190 note mk_u: decimal digits of v; mk_u2: two digits, zero padded (v < 100) 191 fn mk_u v ulong to void 192 b = new uchar 24 0 193 x = v 194 i = ulong 24 195 while true bound 24 196 i = sub i 1 197 put b i uchar add 48 rem x 10 198 x = div x 10 199 if eq x 0 200 break 201 end 202 end 203 for j ulong sub 24 i bound 24 204 mk_b get b add i j 205 end 206 end 207 208 fn mk_u2 v ulong to void 209 mk_b uchar add 48 div v 10 210 mk_b uchar add 48 rem v 10 211 end 212 213 note ---- words ---- 214 note mk_wordb: a pseudo-word of 2..9 letters (consonant, vowel, ...) into b at n; cap: capital first 215 note letter; returns the new length 216 fn mk_wordb b edit uchar * n ulong cap bool to ulong 217 k = add 2 mk_rn 8 218 p = n 219 for i ulong k bound 16 220 c = get mkt_cons mk_rn len mkt_cons 221 if eq rem i 2 1 222 c = get mkt_vow mk_rn len mkt_vow 223 end 224 if and cap eq i 0 225 c = sub c 32 226 end 227 put b p c 228 p = add p 1 229 end 230 ret p 231 end 232 233 fn mk_word cap bool to void 234 b = new uchar 32 0 235 n = mk_wordb b 0 cap 236 mk_t part b 0 n 237 end 238 239 note mk_u8: append one UTF-8 letter to b at n: 0 e-acute, 1 u-umlaut, 2 sharp s, 3 euro sign 240 fn mk_u8 b edit uchar * n ulong k ulong to ulong 241 if eq k 3 242 put b n 226 243 put b add n 1 130 244 put b add n 2 172 245 ret add n 3 246 end 247 c = uchar 169 248 if eq k 1 249 c = 188 250 end 251 if eq k 2 252 c = 159 253 end 254 put b n 195 255 put b add n 1 c 256 ret add n 2 257 end 258 259 note mk_subj: the plain ASCII subject of message j into b (from j's own subject stream, so a reply 260 note repeats it): 2..5 words, or 1..2 words when j is of kind 3 (its encoded word stays <= 75 261 note characters); returns the length (at most 49) 262 fn mk_subj b edit uchar * j ulong to ulong 263 keep = get mk_g MKG_RNG 264 put mk_g MKG_RNG mk_mix add get mk_g MKG_SMIX mul j 2 265 w = add 2 mk_rn 4 266 if eq rem j 5 3 267 w = add 1 mk_rn 2 268 end 269 n = ulong 0 270 for i ulong w bound 8 271 if gt i 0 272 put b n 32 273 n = add n 1 274 end 275 n = mk_wordb b n eq i 0 276 end 277 put mk_g MKG_RNG keep 278 ret n 279 end 280 281 note ---- encoders ---- 282 note mk_b64q: the 4 characters of the 24-bit group v that holds k (1..3) input bytes, "=" padded 283 fn mk_b64q v ulong k ulong to void 284 mk_b get mkt_b64 and shr v 18 63 285 mk_b get mkt_b64 and shr v 12 63 286 if gt k 1 287 mk_b get mkt_b64 and shr v 6 63 288 else 289 mk_b 61 290 end 291 if gt k 2 292 mk_b get mkt_b64 and v 63 293 else 294 mk_b 61 295 end 296 end 297 298 note mk_b64s: one byte into the streaming base64 body encoder (lines of 76 characters) 299 fn mk_b64s c uchar to void 300 a = or shl get mk_g MKG_ACC 8 ulong c 301 k = add get mk_g MKG_NACC 1 302 if lt k 3 303 put mk_g MKG_ACC a 304 put mk_g MKG_NACC k 305 ret 306 end 307 mk_b64q a 3 308 put mk_g MKG_ACC 0 309 put mk_g MKG_NACC 0 310 col = add get mk_g MKG_COL 4 311 if ge col 76 312 mk_b 10 313 col = ulong 0 314 end 315 put mk_g MKG_COL col 316 end 317 318 note mk_b64e: end of a base64 body: the last group padded, the last line ended 319 fn mk_b64e to void 320 k = get mk_g MKG_NACC 321 if gt k 0 322 a = shl get mk_g MKG_ACC mul sub 3 k 8 323 mk_b64q a k 324 put mk_g MKG_COL add get mk_g MKG_COL 4 325 end 326 if gt get mk_g MKG_COL 0 327 mk_b 10 328 end 329 put mk_g MKG_ACC 0 330 put mk_g MKG_NACC 0 331 put mk_g MKG_COL 0 332 end 333 334 note mk_b64v: base64 of b[0, n) with no line breaks (an RFC 2047 B encoded word) 335 fn mk_b64v b view uchar * n ulong to void 336 i = ulong 0 337 while lt i n bound `9223372036854775807` 338 k = sub n i 339 if gt k 3 340 k = 3 341 end 342 v = ulong 0 343 for j ulong 3 344 v = shl v 8 345 if lt j k 346 v = or v ulong get b add i j 347 end 348 end 349 mk_b64q v k 350 i = add i k 351 end 352 end 353 354 fn mk_alnum c uchar to bool 355 if and ge c 97 le c 122 356 ret true 357 end 358 if and ge c 65 le c 90 359 ret true 360 end 361 ret and ge c 48 le c 57 362 end 363 364 note mk_hex3: "=XX" for byte c 365 fn mk_hex3 c uchar to void 366 mk_b 61 367 mk_b get mkt_hexu ulong shr c 4 368 mk_b get mkt_hexu ulong and c 15 369 end 370 371 note mk_qwc: one byte of an RFC 2047 Q encoded word: space "_", letters and digits as is, else "=XX" 372 fn mk_qwc c uchar to void 373 if eq c 32 374 mk_b 95 375 ret 376 end 377 if mk_alnum c 378 mk_b c 379 ret 380 end 381 mk_hex3 c 382 end 383 384 note mk_qpc: one byte of a quoted-printable body: "=", bytes >= 127 and control bytes other than LF 385 note become "=XX"; LF is a hard line break; a soft break "=" LF keeps every line at most 76 characters 386 fn mk_qpc c uchar to void 387 if eq c 10 388 mk_b 10 389 put mk_g MKG_COL 0 390 ret 391 end 392 w = ulong 1 393 if or or eq c 61 ge c 127 lt c 32 394 w = 3 395 end 396 col = get mk_g MKG_COL 397 if gt add col w 75 398 mk_b 61 399 mk_b 10 400 col = ulong 0 401 end 402 if eq w 3 403 mk_hex3 c 404 else 405 mk_b c 406 end 407 put mk_g MKG_COL add col w 408 end 409 410 fn mk_bq c uchar qp bool to void 411 if qp 412 mk_qpc c 413 ret 414 end 415 mk_b c 416 end 417 418 note ---- bodies ---- 419 note mk_wordo: one body word; in a QP body about 1 word in 6 gets a UTF-8 letter, 1 in 20 an "=" 420 fn mk_wordo qp bool to void 421 b = new uchar 32 0 422 n = mk_wordb b 0 false 423 if qp 424 if eq mk_rn 6 0 425 n = mk_u8 b n mk_rn 4 426 end 427 if eq mk_rn 20 0 428 put b n 61 429 n = add n 1 430 end 431 end 432 for i ulong n bound 32 433 mk_bq get b i qp 434 end 435 end 436 437 note mk_line: 4..12 words separated by spaces, then LF 438 fn mk_line qp bool to void 439 w = add 4 mk_rn 9 440 for x ulong w bound 16 441 if gt x 0 442 mk_bq 32 qp 443 end 444 mk_wordo qp 445 end 446 mk_bq 10 qp 447 end 448 449 note mk_text: 2..31 lines 450 fn mk_text qp bool to void 451 put mk_g MKG_COL 0 452 n = add 2 mk_rn 30 453 for x ulong n bound 64 454 mk_line qp 455 end 456 end 457 458 fn mk_bnd i ulong to void 459 mk_t mkt_bnd 460 mk_u i 461 mk_b 120 462 mk_u get mk_g MKG_SEED 463 end 464 465 fn mk_delim i ulong last bool to void 466 mk_b 45 467 mk_b 45 468 mk_bnd i 469 if last 470 mk_b 45 471 mk_b 45 472 end 473 mk_b 10 474 end 475 476 note mk_multi: headers from MIME-Version on, and the body of a kind 1 message 477 fn mk_multi i ulong to void 478 mk_t mkt_mime 479 mk_t mkt_ctmix 480 mk_bnd i 481 mk_t mkt_qnl 482 mk_b 10 483 mk_t mkt_pre 484 mk_delim i false 485 mk_t mkt_ctplain 486 mk_b 10 487 mk_text false 488 mk_delim i false 489 mk_t mkt_ctoct 490 mk_u i 491 mk_t mkt_bin 492 mk_t mkt_cdatt 493 mk_u i 494 mk_t mkt_bin 495 mk_t mkt_cteb64 496 mk_b 10 497 put mk_g MKG_COL 0 498 n = add 64 mk_rn 16384 499 for x ulong n bound `9223372036854775807` 500 mk_b64s uchar and mk_rnd 255 501 end 502 mk_b64e 503 mk_delim i true 504 end 505 506 fn mk_body i ulong k ulong to void 507 if eq k 1 508 mk_multi i 509 ret 510 end 511 if eq k 0 512 mk_b 10 513 mk_text false 514 ret 515 end 516 mk_t mkt_mime 517 if eq k 2 518 mk_t mkt_ctutf 519 mk_t mkt_cteqp 520 mk_b 10 521 mk_text true 522 ret 523 end 524 if eq k 3 525 mk_t mkt_ctutf 526 else 527 mk_t mkt_ctplain 528 end 529 mk_b 10 530 mk_text false 531 end 532 533 note ---- headers ---- 534 note mk_date: "Date: Www, DD Mon YYYY HH:MM:SS +0000" LF for epoch seconds t (UTC; 1970-01-01 a Thursday) 535 fn mk_date t ulong to void 536 days = div t 86400 537 sec = rem t 86400 538 c = ulong civil long days 539 y = div c 10000 540 m = rem div c 100 100 541 d = rem c 100 542 w = rem add days 4 7 543 mk_t mkt_hdate 544 for i ulong 3 545 mk_b get mkt_wd add mul w 3 i 546 end 547 mk_t mkt_comsp 548 mk_u2 d 549 mk_b 32 550 for i ulong 3 551 mk_b get mkt_mon add mul sub m 1 3 i 552 end 553 mk_b 32 554 mk_u y 555 mk_b 32 556 mk_u2 div sec 3600 557 mk_b 58 558 mk_u2 rem div sec 60 60 559 mk_b 58 560 mk_u2 rem sec 60 561 mk_t mkt_utc 562 end 563 564 note mk_from: "From: Name Name "; enc: the display name has a UTF-8 letter and is 565 note one Q encoded word 566 fn mk_from enc bool to void 567 nb = new uchar 128 0 568 n = mk_wordb nb 0 true 569 if enc 570 n = mk_u8 nb n 0 571 end 572 put nb n 32 573 n = mk_wordb nb add n 1 true 574 mk_t mkt_hfrom 575 if enc 576 mk_t mkt_ewq 577 for x ulong n bound 128 578 mk_qwc get nb x 579 end 580 mk_t mkt_ewe 581 else 582 mk_t part nb 0 n 583 end 584 mk_t mkt_lt 585 mk_word false 586 mk_b uchar add 48 mk_rn 10 587 mk_t mkt_atgt 588 end 589 590 fn mk_cc to void 591 mk_t mkt_hcc 592 mk_word false 593 mk_t mkt_atnl 594 end 595 596 note mk_hsubj: the Subject line of message i of kind k (j: the parent of a reply) 597 fn mk_hsubj i ulong k ulong j ulong to void 598 sb = new uchar 256 0 599 mk_t mkt_hsubj 600 if eq k 4 601 mk_t mkt_re 602 n1 = mk_subj sb j 603 mk_t part sb 0 n1 604 mk_b 10 605 ret 606 end 607 n = mk_subj sb i 608 if ne k 3 609 mk_t part sb 0 n 610 mk_b 10 611 ret 612 end 613 put sb n 32 614 n = mk_u8 sb add n 1 mk_rn 4 615 if eq mk_rn 2 0 616 mk_t mkt_ewb 617 mk_b64v sb n 618 else 619 mk_t mkt_ewq 620 for x ulong n bound 256 621 mk_qwc get sb x 622 end 623 end 624 mk_t mkt_ewe 625 mk_b 10 626 end 627 628 note mk_mid: header text t, then "i.sSEED@example.org>" LF 629 fn mk_mid t view uchar * i ulong to void 630 mk_t t 631 mk_u i 632 mk_t mkt_mids 633 mk_u get mk_g MKG_SEED 634 mk_t mkt_atgt 635 end 636 637 note mk_msg: the bytes of message i through mk_b 638 fn mk_msg i ulong to void 639 k = rem i 5 640 smix = get mk_g MKG_SMIX 641 put mk_g MKG_RNG mk_mix add smix add mul i 2 1 642 j = ulong 0 643 if eq k 4 644 j = mk_rn i 645 end 646 mk_date get mk_g MKG_T 647 mk_from eq k 3 648 mk_t mkt_hto 649 if eq mk_rn 4 0 650 mk_cc 651 end 652 mk_hsubj i k j 653 mk_mid mkt_hmid i 654 if eq k 4 655 mk_mid mkt_hirt j 656 mk_mid mkt_hrefs j 657 end 658 mk_body i k 659 end 660 661 note ---- files ---- 662 note mk_errno: one stderr line: t, the decimal of -e, ": ", the path in gp 663 fn mk_errno t view uchar * e long to void 664 b = new uchar 24 0 665 x = ulong 0 666 if lt e 0 667 x = ulong neg e 668 end 669 i = ulong 24 670 while true bound 24 671 i = sub i 1 672 put b i uchar add 48 rem x 10 673 x = div x 10 674 if eq x 0 675 break 676 end 677 end 678 r = write 2 t 0 len t 679 r = write 2 b i sub 24 i 680 r = write 2 mkt_colsp 0 len mkt_colsp 681 r = write 2 gp 0 get gv VPL 682 r = write 2 mkt_nl 0 1 683 end 684 685 fn mk_err t view uchar * to void 686 r = write 2 t 0 len t 687 r = write 2 mkt_nl 0 1 688 end 689 690 fn mk_proot to void 691 p_reset 692 p_s S_AUX 0 s_len S_AUX 693 end 694 695 note mk_mkroot: ROOT, ROOT/cur, ROOT/new, ROOT/tmp; 0, 1 (unusable path or ROOT exists), 6 (I/O) 696 fn mk_mkroot to int 697 mk_proot 698 if not p_ok 699 mk_err mkt_epath 700 ret 1 701 end 702 r = p_mkdir 703 if lt r 0 704 mk_errno mkt_eroot r 705 if eq r -17 706 ret 1 707 end 708 ret 6 709 end 710 for k ulong 3 711 mk_proot 712 if eq k 0 713 p_t mkt_cur 714 end 715 if eq k 1 716 p_t mkt_new 717 end 718 if eq k 2 719 p_t mkt_tmp 720 end 721 r = p_mkdir 722 if lt r 0 723 mk_errno mkt_eroot r 724 ret 6 725 end 726 end 727 ret 0 728 end 729 730 note mk_open: create (exclusively, never through a symlink) the file of message i with epoch t 731 fn mk_open i ulong t ulong to long 732 mk_proot 733 if eq rem i 3 0 734 p_t mkt_new 735 else 736 p_t mkt_cur 737 end 738 p_c 47 739 p_u t 740 p_t mkt_m 741 p_u i 742 p_c 80 743 p_u get mk_g MKG_SEED 744 p_t mkt_host 745 if ne rem i 3 0 746 p_t mkt_flag 747 end 748 if not p_ok 749 ret -36 750 end 751 ret fopen gp 0 get gv VPL OEXCL MK_FMODE 752 end 753 754 note mk_one: write message i; 0 or 6 (I/O, stderr names errno and path; a partial file is removed) 755 fn mk_one i ulong to int 756 x = mk_mix add get mk_g MKG_SMIX add mul i 2 1 757 t = add add `1735689600` mul i 600 rem x 600 758 fd = mk_open i t 759 if lt fd 0 760 mk_errno mkt_ecreate fd 761 ret 6 762 end 763 put mk_g MKG_FD add ulong fd 1 764 put mk_g MKG_WN 0 765 put mk_g MKG_FB 0 766 put mk_g MKG_T t 767 mk_msg i 768 z = mk_flush 769 c = fclose int fd 770 put mk_g MKG_FD 0 771 if lt c 0 772 mk_fail c 773 end 774 if ne get mk_g MKG_FAIL 0 775 zu = unlink gp 0 get gv VPL 776 mk_errno mkt_ewrite neg long get mk_g MKG_ERRNO 777 ret 6 778 end 779 put mk_g MKG_TB add get mk_g MKG_TB get mk_g MKG_FB 780 k = add MKG_KIND rem i 5 781 put mk_g k add get mk_g k 1 782 if eq rem i 3 0 783 put mk_g MKG_NEW add get mk_g MKG_NEW 1 784 else 785 put mk_g MKG_CUR add get mk_g MKG_CUR 1 786 end 787 ret 0 788 end 789 790 note mk_gen: the Maildir at the path in store S_AUX with n messages from seed (layout at the top); 791 note 0, 1 (unusable path or the root exists), 6 (I/O). Totals stay in mk_g for mk_osum. 792 fn mk_gen n ulong seed ulong to int 793 for x ulong 32 794 put mk_g x 0 795 end 796 put mk_g MKG_SEED seed 797 put mk_g MKG_N n 798 put mk_g MKG_SMIX mk_mix add seed `11400714819323198485` 799 r = mk_mkroot 800 if ne r 0 801 ret r 802 end 803 for i ulong n bound `9223372036854775807` 804 r = mk_one i 805 if ne r 0 806 ret r 807 end 808 end 809 ret 0 810 end 811 812 note mk_bytes: total bytes of the messages written by the last mk_gen 813 fn mk_bytes to ulong 814 ret get mk_g MKG_TB 815 end 816 817 note ---- report ---- 818 fn mk_okv t view uchar * v ulong to void 819 o_raw t 820 o_digits v 821 end 822 823 note mk_osum: "N=.. seed=.. bytes=.. new=.. cur=.. plain=.. multipart=.. qp=.. encoded_subject=.. reply=.." 824 fn mk_osum to void 825 mk_okv mkt_kn get mk_g MKG_N 826 mk_okv mkt_kseed get mk_g MKG_SEED 827 mk_okv mkt_kbytes get mk_g MKG_TB 828 mk_okv mkt_knew get mk_g MKG_NEW 829 mk_okv mkt_kcur get mk_g MKG_CUR 830 mk_okv mkt_kplain get mk_g MKG_KIND 831 mk_okv mkt_kmulti get mk_g add MKG_KIND 1 832 mk_okv mkt_kqp get mk_g add MKG_KIND 2 833 mk_okv mkt_kenc get mk_g add MKG_KIND 3 834 mk_okv mkt_kreply get mk_g add MKG_KIND 4 835 end 836 837 note ---- arguments ---- 838 note mk_argnum: argument idx as a decimal ulong; mk_g cell 30 becomes 1 when it is empty, holds a 839 note byte other than 0-9, or is above `18446744073709551615` (the ulong range, a machine boundary) 840 fn mk_argnum idx ulong to ulong 841 b = new uchar 131072 0 842 k = argread idx b 0 131072 843 if le k 0 844 put mk_g MKG_BAD 1 845 ret 0 846 end 847 v = ulong 0 848 for i ulong ulong k bound 131072 849 c = get b i 850 if or lt c 48 gt c 57 851 put mk_g MKG_BAD 1 852 ret 0 853 end 854 dg = ulong sub c 48 855 if gt v `1844674407370955161` 856 put mk_g MKG_BAD 1 857 ret 0 858 end 859 if eq v `1844674407370955161` 860 if gt dg 5 861 put mk_g MKG_BAD 1 862 ret 0 863 end 864 end 865 v = add mul v 10 dg 866 end 867 ret v 868 end 869 870 note ---- exact rates ---- 871 note mk_digits: the decimal digits (values 0..9, most significant first) of a into da; the count 872 fn mk_digits a ulong da edit uchar 24 to ulong 873 t = new uchar 24 0 874 x = a 875 n = ulong 0 876 while true bound 24 877 put t n uchar rem x 10 878 x = div x 10 879 n = add n 1 880 if eq x 0 881 break 882 end 883 end 884 for i ulong n bound 24 885 put da i get t sub sub n i 1 886 end 887 ret n 888 end 889 890 note bn_ratio: a * 10^k / b printed with d decimals, truncated (not rounded). Exact schoolbook long 891 note division over the digits of a followed by k + d zeros: the remainder r < b, so each step's 892 note r*10 + 9 <= 10b - 1 fits a ulong when b <= `1844674407370955161` = floor((2^64-1)/10) (ns: 58 years). 893 note b = 0 or b above that prints "n/a" (a machine boundary of 64-bit arithmetic, never a wrong number). 894 note messages/s = N * 10^9 / wall_ns (k 9); decimal MB/s = bytes * 10^3 / wall_ns (k 3), MB = 10^6 bytes. 895 fn bn_ratio a ulong k ulong b ulong d ulong to void 896 if or eq b 0 gt b `1844674407370955161` 897 o_raw mkt_na 898 ret 899 end 900 da = new uchar 24 0 901 na = mk_digits a da 902 ip = add na k 903 bn_ldiv da na ip add ip d b 904 end 905 906 note bn_ldiv: the quotient digits of (digits da[0, na) then zeros) / b, positions 0..tot-1; a "." 907 note before position ip; leading zeros of the integer part dropped (one "0" kept) 908 fn bn_ldiv da view uchar 24 na ulong ip ulong tot ulong b ulong to void 909 r = ulong 0 910 lead = true 911 for i ulong tot bound `9223372036854775807` 912 if eq i ip 913 if lead 914 o_b 48 915 lead = false 916 end 917 o_b 46 918 end 919 dg = ulong 0 920 if lt i na 921 dg = ulong get da i 922 end 923 r = add mul r 10 dg 924 q = div r b 925 r = rem r b 926 if lt i ip 927 if or ne q 0 not lead 928 o_b uchar add 48 q 929 lead = false 930 end 931 else 932 o_b uchar add 48 q 933 end 934 end 935 if lead 936 o_b 48 937 end 938 end