1+ /*
2+ * Copyright 2016-2019 JetBrains s.r.o.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package tests.stress
18+
19+ import kotlin.test.AfterTest
20+ import kotlin.test.BeforeTest
21+ import kotlin.time.*
22+
23+ @UseExperimental(ExperimentalTime ::class )
24+ abstract class ExecutionTimeMeasuringTest {
25+ private var clockMark: ClockMark ? = null
26+
27+ private fun markExecutionStart () {
28+ clockMark = MonoClock .markNow()
29+ }
30+
31+ private fun printExecutionTime () {
32+ val nonNullClockMark = clockMark ? : throw IllegalStateException (" markExecutionStart() must be called first" )
33+ val elapsed = nonNullClockMark.elapsedNow()
34+
35+ if (elapsed > 3 .seconds) {
36+ print (" #" .repeat(20 ) + " " )
37+ }
38+ println (" Execution time: ${elapsed.toString(DurationUnit .MILLISECONDS )} " )
39+
40+ clockMark = null
41+ }
42+
43+ @BeforeTest
44+ fun before () {
45+ markExecutionStart()
46+ }
47+
48+ @AfterTest
49+ fun after () {
50+ printExecutionTime()
51+ }
52+ }
0 commit comments