File: targetunicode-bench.py

package info (click to toggle)
pypy 7.3.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,660 kB
  • sloc: python: 1,419,707; ansic: 64,313; cpp: 3,290; sh: 2,763; makefile: 540; xml: 256; asm: 213; lisp: 45; awk: 4
file content (45 lines) | stat: -rw-r--r-- 1,317 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

from rpython.rlib import rutf8
from rpython.rlib.rstring import StringBuilder, UnicodeBuilder
from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb

l = ["u" * 100 + str(i) for i in range(100)]
u_l = [unicode("u" * 100 + str(i)) for i in range(100)]

def descr_upper(s):
    builder = rutf8.Utf8StringBuilder(len(s))
    for ch in rutf8.Utf8StringIterator(s):
        ch = unicodedb.toupper(ch)
        builder.append_code(ch)
    return builder.build()
descr_upper._dont_inline_ = True

def descr_upper_s(s):
    builder = StringBuilder(len(s))
    for i in range(len(s)):
        ch = s[i]
        builder.append(chr(unicodedb.toupper(ord(ch))))
    return builder.build()

def descr_upper_u(s):
    builder = UnicodeBuilder(len(s))
    for ch in s:
        builder.append(unichr(unicodedb.toupper(ord(ch))))
    return builder.build()

def main(argv):
    res_l = ["foo"]
    res_l_2 = [u"foo"]
    if len(argv) > 2 and argv[2] == "s":
        for i in range(int(argv[1])):
            res_l[0] = descr_upper_s(l[i % 100])
    elif len(argv) > 2 and argv[2] == "u":
        for i in range(int(argv[1])):
            res_l_2[0] = descr_upper_u(u_l[i % 100])
    else:
        for i in range(int(argv[1])):
            res_l[0] = descr_upper(l[i % 100])
    return 0

def target(*args):
    return main