File: __init__.py

package info (click to toggle)
suds 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,836 kB
  • sloc: python: 18,367; makefile: 198; sh: 41
file content (68 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (6)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify it under
# the terms of the (LGPL) GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Library Lesser General Public License
# for more details at ( http://www.gnu.org/licenses/lgpl.html ).
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# written by: Jurko Gospodnetić ( jurko.gospodnetic@pke.hr )

"""
Package containing different suds profiling scripts used for comparing
different suds detail implementations or running them under different Python
interpreter versions.

"""

import sys
import timeit


class ProfilerBase(object):
    """Base class for profilers implemented in this project."""

    def __init__(self, show_each_timing=False, show_minimum=True):
        self.show_each_timing = show_each_timing
        self.show_minimum = show_minimum

    def timeit(self, method_name, number, repeat=5):
        print("Timing '%s' (looping %d times, %d timings)" % (method_name,
            number, repeat))
        # We want to pass 'self' as input to the timing functionality
        # implemented in the timeit module, but its interface only allows
        # sharing data via global storage.
        timit_input_storage = "__temporary_timeit_input_data_storage__12345"
        assert not hasattr(sys, timit_input_storage)
        try:
            code = "p.%s()" % (method_name,)
            setup_code = "import sys;p = sys.%s" % (timit_input_storage,)
            setattr(sys, timit_input_storage, self)
            timer = timeit.Timer(code, setup=setup_code)
            times = []
            try:
                for i in range(repeat):
                    time = timer.timeit(number)
                    times.append(time)
                    if self.show_each_timing:
                        print("%d. %s" % (time,))
            except (KeyboardInterrupt, SystemExit):
                raise
            except Exception:
                timer.print_exc()
            else:
                if self.show_minimum:
                    print(min(times))
            return times
        finally:
            try:
                delattr(sys, timit_input_storage)
            except AttributeError:
                pass