• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / ZODB / 18153960591

01 Oct 2025 06:50AM UTC coverage: 83.781% (-0.03%) from 83.811%
18153960591

Pull #415

github

web-flow
Update docs/articles/old-guide/convert_zodb_guide.py

Co-authored-by: Michael Howitz <icemac@gmx.net>
Pull Request #415: Apply the latest zope.meta templates

2441 of 3542 branches covered (68.92%)

193 of 257 new or added lines in 48 files covered. (75.1%)

12 existing lines in 6 files now uncovered.

13353 of 15938 relevant lines covered (83.78%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ZODB/tests/speed.py
1
import getopt
×
2
import os
×
3
import string
×
4
import sys
×
5
import time
×
6

7
import persistent
×
8
import transaction
×
9

10
import ZODB
×
11
import ZODB.FileStorage
×
12

13

14
##############################################################################
15
#
16
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
17
# All Rights Reserved.
18
#
19
# This software is subject to the provisions of the Zope Public License,
20
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
21
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
22
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
24
# FOR A PARTICULAR PURPOSE
25
#
26
##############################################################################
27
usage = """Test speed of a ZODB storage
×
28

29
Options:
30

31
    -d file    The data file to use as input.
32
               The default is this script.
33

34
    -n n       The number of repititions
35

36
    -s module  A module that defines a 'Storage'
37
               attribute, which is an open storage.
38
               If not specified, a FileStorage will ne
39
               used.
40

41
    -z         Test compressing data
42

43
    -D         Run in debug mode
44

45
    -L         Test loads as well as stores by minimizing
46
               the cache after eachrun
47

48
    -M         Output means only
49
"""
50

51
sys.path.insert(0, os.getcwd())
×
52

53

54
class P(persistent.Persistent):
×
55
    pass
×
56

57

58
def main(args):
×
59

60
    opts, args = getopt.getopt(args, 'zd:n:Ds:LM')
×
61
    z = s = None
×
62
    data = sys.argv[0]
×
63
    nrep = 5
×
64
    minimize = 0
×
65
    detailed = 1
×
66
    for o, v in opts:
×
67
        if o == '-n':
×
68
            nrep = string.atoi(v)
×
69
        elif o == '-d':
×
70
            data = v
×
71
        elif o == '-s':
×
72
            s = v
×
73
        elif o == '-z':
×
74
            global zlib
75
            import zlib
×
76
            z = compress
×
77
        elif o == '-L':
×
78
            minimize = 1
×
79
        elif o == '-M':
×
80
            detailed = 0
×
81
        elif o == '-D':
×
82
            os.environ['STUPID_LOG_FILE'] = ''
×
83
            os.environ['STUPID_LOG_SEVERITY'] = '-999'
×
84

85
    if s:
×
86
        s = __import__(s, globals(), globals(), ('__doc__',))
×
87
        s = s.Storage
×
88
    else:
89
        s = ZODB.FileStorage.FileStorage('zeo_speed.fs', create=1)
×
90

91
    with open(data) as fp:
×
92
        data = fp.read()
×
93
    db = ZODB.DB(s,
×
94
                 # disable cache deactivation
95
                 cache_size=4000,
96
                 cache_deactivate_after=6000,)
97

98
    results = {1: 0, 10: 0, 100: 0, 1000: 0}
×
99
    for j in range(nrep):
×
100
        for r in 1, 10, 100, 1000:
×
101
            t = time.time()
×
102
            jar = db.open()
×
103
            transaction.begin()
×
104
            rt = jar.root()
×
105
            key = 's%s' % r
×
106
            if key in rt:
×
107
                p = rt[key]
×
108
            else:
109
                rt[key] = p = P()
×
110
            for i in range(r):
×
111
                if z is not None:
×
112
                    d = z(data)
×
113
                else:
114
                    d = data
×
115
                v = getattr(p, str(i), P())
×
116
                v.d = d
×
117
                setattr(p, str(i), v)
×
118
            transaction.commit()
×
119
            jar.close()
×
NEW
120
            t = time.time() - t
×
121
            if detailed:
×
NEW
122
                sys.stderr.write(f"{j}\t{r}\t{t:.4f}\n")
×
123
                sys.stdout.flush()
×
NEW
124
            results[r] = results[r] + t
×
125
            rt = d = p = v = None  # release all references
×
126
            if minimize:
×
127
                time.sleep(3)
×
128
                jar.cacheMinimize(3)
×
129

130
    if detailed:
×
NEW
131
        print('-' * 24)
×
132
    for r in 1, 10, 100, 1000:
×
NEW
133
        t = results[r] / nrep
×
NEW
134
        sys.stderr.write(
×
135
            f"mean:\t{r}\t{t:.4f}\t{t / r:.4f} (s/o)\n")
136

137
    db.close()
×
138

139

140
def compress(s):
×
141
    c = zlib.compressobj()
×
142
    o = c.compress(s)
×
NEW
143
    return o + c.flush()
×
144

145

146
if __name__ == '__main__':
147
    main(sys.argv[1:])
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc