source: flex_extract.git/python/pythontest/TestInstallTar/flex_extract_v7.1/python/profiling.py @ 2fb99de

devfeature/makefilesorigin/task/language-editingsysinstalltask/language-editing
Last change on this file since 2fb99de was 2fb99de, checked in by Anne Philipp <anne.philipp@…>, 2 years ago

introduced config with path definitions and changed py files accordingly; Installation works; some tests were added for tarball making; Problems in submission to ecgate

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#************************************************************************
4# ToDo AP
5# - check license of book content
6#************************************************************************
7#*******************************************************************************
8#
9# @Author: Anne Philipp (University of Vienna)
10#
11# @Date: March 2018
12#
13# @License:
14#    (C) Copyright 2018.
15#
16#    This software is licensed under the terms of the Apache Licence Version 2.0
17#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
18#
19# @Program functionality:
20#    This module is not part of flex_extract. It is just used for testing and
21#    performance analysis of some functions.
22#
23# @Program Content:
24#    - timefn
25#
26#*******************************************************************************
27
28# ------------------------------------------------------------------------------
29# MODULES
30# ------------------------------------------------------------------------------
31from functools import wraps
32import time
33
34# ------------------------------------------------------------------------------
35# FUNCTION
36# ------------------------------------------------------------------------------
37def timefn(fn):
38    '''
39    @Description:
40        Decorator function. It takes the inner function as an argument.
41    '''
42    @wraps(fn)
43    def measure_time(*args, **kwargs):
44        '''
45        @Descripton:
46            Passes the arguments through fn for execution. Around the
47            execution of fn the time is captured to execute the fn function
48            and prints the result along with the function name.
49
50            This is taken from the book "High Performance Python" from
51            Micha Gorelick and Ian Ozsvald, O'Reilly publisher, 2014,
52            ISBN: 978-1-449-36159-4
53
54        @Input:
55            *args: undefined
56                A variable number of positional arguments.
57
58            **kwargs: undefined
59                A variable number of key/value arguments.
60
61        @Return:
62            <nothing>
63        '''
64
65        t1 = time.time()
66        result = fn(*args, **kwargs)
67        t2 = time.time()
68        print "@timefn:" + fn.func_name + " took " + str(t2 - t1) + " seconds"
69
70        return result
71
72    return measure_time
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG