Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions bench/char-alphabetic-p.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;; char-alphabetic? 性能测试

(import (scheme base)
(scheme char)
(liii timeit)
)

(define iterations 100000)

(define (bench-ascii-letter)
(timeit (lambda () (char-alphabetic? #\a)) '() iterations)
)

(define (bench-ascii-digit)
(timeit (lambda () (char-alphabetic? #\5)) '() iterations)
)

(define (bench-ascii-space)
(timeit (lambda () (char-alphabetic? #\space)) '() iterations)
)

(define (bench-unicode-cjk)
(timeit (lambda () (char-alphabetic? #\x4E2D)) '() iterations)
)

(define (bench-unicode-symbol)
(timeit (lambda () (char-alphabetic? #\x2600)) '() iterations)
)

(define (bench-beyond-max)
(timeit (lambda () (char-alphabetic? #\x40000)) '() iterations)
)

(display "=== char-alphabetic? 性能测试 ===\n")
(display "迭代次数: ")
(display iterations)
(display "\n\n")

(display "ASCII 字母 (#\\a) -> 命中:\n")
(display " ")
(display (bench-ascii-letter))
(display " 秒\n\n")

(display "ASCII 数字 (#\\5) -> 未命中:\n")
(display " ")
(display (bench-ascii-digit))
(display " 秒\n\n")

(display "ASCII 空格 -> 未命中:\n")
(display " ")
(display (bench-ascii-space))
(display " 秒\n\n")

(display "Unicode CJK (#\\x4E2D) -> 命中:\n")
(display " ")
(display (bench-unicode-cjk))
(display " 秒\n\n")

(display "Unicode 符号 (#\\x2600) -> 未命中:\n")
(display " ")
(display (bench-unicode-symbol))
(display " 秒\n\n")

(display "超出上届 (#\\x40000) -> 快速拒绝:\n")
(display " ")
(display (bench-beyond-max))
(display " 秒\n")
67 changes: 67 additions & 0 deletions bench/char-downcase.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;; char-downcase 性能测试

(import (scheme base)
(scheme char)
(liii timeit)
)

(define iterations 100000)

(define (bench-ascii-upper)
(timeit (lambda () (char-downcase #\A)) '() iterations)
)

(define (bench-ascii-lower)
(timeit (lambda () (char-downcase #\a)) '() iterations)
)

(define (bench-ascii-digit)
(timeit (lambda () (char-downcase #\5)) '() iterations)
)

(define (bench-ascii-space)
(timeit (lambda () (char-downcase #\space)) '() iterations)
)

(define (bench-unicode-upper)
(timeit (lambda () (char-downcase #\x391)) '() iterations)
)

(define (bench-unicode-lower)
(timeit (lambda () (char-downcase #\x3B1)) '() iterations)
)

(display "=== char-downcase 性能测试 ===\n")
(display "迭代次数: ")
(display iterations)
(display "\n\n")

(display "ASCII 大写 (#\\A) -> 命中前部分支:\n")
(display " ")
(display (bench-ascii-upper))
(display " 秒\n\n")

(display "ASCII 小写 (#\\a) -> 未命中:\n")
(display " ")
(display (bench-ascii-lower))
(display " 秒\n\n")

(display "ASCII 数字 (#\\5) -> 未命中:\n")
(display " ")
(display (bench-ascii-digit))
(display " 秒\n\n")

(display "ASCII 空格 -> 未命中:\n")
(display " ")
(display (bench-ascii-space))
(display " 秒\n\n")

(display "Unicode 大写 (#\\x391) -> 命中中后部分支:\n")
(display " ")
(display (bench-unicode-upper))
(display " 秒\n\n")

(display "Unicode 小写 (#\\x3B1) -> 未命中:\n")
(display " ")
(display (bench-unicode-lower))
(display " 秒\n")
67 changes: 67 additions & 0 deletions bench/char-foldcase.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;; char-foldcase 性能测试

(import (scheme base)
(scheme char)
(liii timeit)
)

(define iterations 100000)

(define (bench-ascii-upper)
(timeit (lambda () (char-foldcase #\A)) '() iterations)
)

(define (bench-ascii-lower)
(timeit (lambda () (char-foldcase #\a)) '() iterations)
)

(define (bench-ascii-digit)
(timeit (lambda () (char-foldcase #\5)) '() iterations)
)

(define (bench-ascii-space)
(timeit (lambda () (char-foldcase #\space)) '() iterations)
)

(define (bench-special-383)
(timeit (lambda () (char-foldcase #\x17F)) '() iterations)
)

(define (bench-special-304)
(timeit (lambda () (char-foldcase #\x130)) '() iterations)
)

(display "=== char-foldcase 性能测试 ===\n")
(display "迭代次数: ")
(display iterations)
(display "\n\n")

(display "ASCII 大写 (#\\A) -> 回退 char-downcase, 命中前部分支:\n")
(display " ")
(display (bench-ascii-upper))
(display " 秒\n\n")

(display "ASCII 小写 (#\\a) -> 回退 char-downcase, 未命中:\n")
(display " ")
(display (bench-ascii-lower))
(display " 秒\n\n")

(display "ASCII 数字 (#\\5) -> 回退 char-downcase, 未命中:\n")
(display " ")
(display (bench-ascii-digit))
(display " 秒\n\n")

(display "ASCII 空格 -> 回退 char-downcase, 未命中:\n")
(display " ")
(display (bench-ascii-space))
(display " 秒\n\n")

(display "特殊码点 #\\x17F -> 命中 foldcase 自身分支:\n")
(display " ")
(display (bench-special-383))
(display " 秒\n\n")

(display "特殊码点 #\\x130 -> 命中 foldcase 自身分支:\n")
(display " ")
(display (bench-special-304))
(display " 秒\n")
67 changes: 67 additions & 0 deletions bench/char-upcase.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;; char-upcase 性能测试

(import (scheme base)
(scheme char)
(liii timeit)
)

(define iterations 100000)

(define (bench-ascii-lower)
(timeit (lambda () (char-upcase #\a)) '() iterations)
)

(define (bench-ascii-upper)
(timeit (lambda () (char-upcase #\A)) '() iterations)
)

(define (bench-ascii-digit)
(timeit (lambda () (char-upcase #\5)) '() iterations)
)

(define (bench-ascii-space)
(timeit (lambda () (char-upcase #\space)) '() iterations)
)

(define (bench-unicode-lower)
(timeit (lambda () (char-upcase #\x3B1)) '() iterations)
)

(define (bench-unicode-upper)
(timeit (lambda () (char-upcase #\x391)) '() iterations)
)

(display "=== char-upcase 性能测试 ===\n")
(display "迭代次数: ")
(display iterations)
(display "\n\n")

(display "ASCII 小写 (#\\a) -> 命中前部分支:\n")
(display " ")
(display (bench-ascii-lower))
(display " 秒\n\n")

(display "ASCII 大写 (#\\A) -> 未命中:\n")
(display " ")
(display (bench-ascii-upper))
(display " 秒\n\n")

(display "ASCII 数字 (#\\5) -> 未命中:\n")
(display " ")
(display (bench-ascii-digit))
(display " 秒\n\n")

(display "ASCII 空格 -> 未命中:\n")
(display " ")
(display (bench-ascii-space))
(display " 秒\n\n")

(display "Unicode 小写 (#\\x3B1) -> 命中中后部分支:\n")
(display " ")
(display (bench-unicode-lower))
(display " 秒\n\n")

(display "Unicode 大写 (#\\x391) -> 未命中:\n")
(display " ")
(display (bench-unicode-upper))
(display " 秒\n")
67 changes: 67 additions & 0 deletions bench/char-whitespace-p.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
;; char-whitespace? 性能测试

(import (scheme base)
(scheme char)
(liii timeit)
)

(define iterations 100000)

(define (bench-space)
(timeit (lambda () (char-whitespace? #\space)) '() iterations)
)

(define (bench-tab)
(timeit (lambda () (char-whitespace? #\tab)) '() iterations)
)

(define (bench-letter)
(timeit (lambda () (char-whitespace? #\a)) '() iterations)
)

(define (bench-digit)
(timeit (lambda () (char-whitespace? #\5)) '() iterations)
)

(define (bench-nbsp)
(timeit (lambda () (char-whitespace? #\xA0)) '() iterations)
)

(define (bench-ideographic-space)
(timeit (lambda () (char-whitespace? #\x3000)) '() iterations)
)

(display "=== char-whitespace? 性能测试 ===\n")
(display "迭代次数: ")
(display iterations)
(display "\n\n")

(display "ASCII 空格 -> 命中:\n")
(display " ")
(display (bench-space))
(display " 秒\n\n")

(display "ASCII tab -> 命中:\n")
(display " ")
(display (bench-tab))
(display " 秒\n\n")

(display "ASCII 字母 (#\\a) -> 未命中:\n")
(display " ")
(display (bench-letter))
(display " 秒\n\n")

(display "ASCII 数字 (#\\5) -> 未命中:\n")
(display " ")
(display (bench-digit))
(display " 秒\n\n")

(display "Unicode nbsp (#\\xA0) -> 命中:\n")
(display " ")
(display (bench-nbsp))
(display " 秒\n\n")

(display "Unicode 全角空格 (#\\x3000) -> 命中:\n")
(display " ")
(display (bench-ideographic-space))
(display " 秒\n")
10 changes: 6 additions & 4 deletions compat/char-alphabetic-p.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(import (scheme char))

(letrec
((loop
(lambda (i end acc count)
Expand All @@ -22,10 +24,10 @@
(if (< cp #x1000)
(if (< cp #x100)
(if (< cp #x10)
(display (string-append "000" (number->string cp 16)))
(display (string-append "00" (number->string cp 16))))
(display (string-append "0" (number->string cp 16))))
(display (number->string cp 16)))
(display (string-append "000" (string-upcase (number->string cp 16))))
(display (string-append "00" (string-upcase (number->string cp 16)))))
(display (string-append "0" (string-upcase (number->string cp 16)))))
(display (string-upcase (number->string cp 16))))
(display ",")
(display (integer->char cp))
(newline))
Expand Down
Loading
Loading