Commit 2f19513 1 parent 29ad652 commit 2f19513 Copy full SHA for 2f19513
File tree 1 file changed +6
-18
lines changed
1 file changed +6
-18
lines changed Original file line number Diff line number Diff line change 1
1
package util
2
2
import scala .collection .mutable
3
3
import scala .collection
4
+ import java .util .concurrent .atomic .AtomicLong
4
5
5
6
case class RegionTimer (name : String ) {
6
- private var total : Long = 0
7
- private var entered : Long = 0
8
- private var inside : Boolean = false
7
+ private val total : AtomicLong = AtomicLong (0 )
9
8
10
9
def within [T ](body : => T ): T = {
11
- enter ()
10
+ val begin = System .currentTimeMillis ()
12
11
val result = body
13
- exit()
12
+ val finish = System .currentTimeMillis()
13
+ val _ = total.addAndGet(finish - begin)
14
14
result
15
15
}
16
16
17
- def enter () = {
18
- require(! inside)
19
- inside = true
20
- entered = System .currentTimeMillis()
21
- }
22
-
23
- def exit () = {
24
- require(inside)
25
- inside = false
26
- total += (System .currentTimeMillis() - entered)
27
- }
28
-
29
- def getTotal () = total
17
+ def getTotal (): Long = total.get
30
18
31
19
override def toString () = {
32
20
s " $name : ${getTotal()} (ms) "
You can’t perform that action at this time.
0 commit comments