MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / __call__

Method __call__

DIEN/wrap_time.py:44–69  ·  view source on GitHub ↗

Summary Args: *args (TYPE): Description **kwargs (TYPE): Description Returns: TYPE: Description

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

42 self.freq = freq
43
44 def __call__(self, *args, **kwargs):
45 """Summary
46
47 Args:
48 *args (TYPE): Description
49 **kwargs (TYPE): Description
50
51 Returns:
52 TYPE: Description
53 """
54 start = time.time()
55 # args contains the caller itself
56 # print args[0] and you will see
57 result = self.func(*args, **kwargs)
58 end = time.time()
59
60 self.call_count += 1
61 self.acc_time += (end - start)
62 if self.call_count > 0 and self.call_count % self.freq == 0:
63 print("Avg time cost of %s%s is %f",
64 self.class_name, self.__name__,
65 self.acc_time / self.call_count)
66 self.call_count = 0
67 self.acc_time = 0.0
68
69 return result
70
71 def __get__(self, instance, cls):
72 """Summary

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected