• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JohnSnowLabs / spark-nlp / 4947838414

pending completion
4947838414

Pull #13796

github

GitHub
Merge 30bdeef19 into ef7906c5e
Pull Request #13796: Add unzip param to downloadModelDirectly in ResourceDownloader

39 of 39 new or added lines in 2 files covered. (100.0%)

8632 of 13111 relevant lines covered (65.84%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/src/main/scala/com/johnsnowlabs/util/Benchmark.scala
1
/*
2
 * Copyright 2017-2022 John Snow Labs
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 com.johnsnowlabs.util
18

19
object Benchmark {
20

21
  private var print = true
1✔
22

23
  def setPrint(v: Boolean): Unit = print = v
×
24

25
  def getPrint: Boolean = print
×
26

27
  def time[R](description: String, forcePrint: Boolean = false)(block: => R): R = {
28
    val t0 = System.nanoTime()
1✔
29
    val result = block
30
    val t1 = System.nanoTime()
1✔
31
    if (print || forcePrint) println(description + ": " + ((t1 - t0) / 1000000000.0) + "sec")
×
32
    result
33
  }
34

35
  def measure(iterations: Integer = 3, forcePrint: Boolean = false, description: String = "Took")(
36
      f: => Any): Double = {
37
    val time = (0 until iterations)
1✔
38
      .map { _ =>
1✔
39
        val t0 = System.nanoTime()
1✔
40
        f
41
        System.nanoTime() - t0
1✔
42
      }
43
      .sum
1✔
44
      .toDouble / iterations
1✔
45

46
    if (print || forcePrint)
1✔
47
      println(s"$description (Avg for $iterations iterations): ${time / 1000000000} sec")
1✔
48

49
    time / 1000000000
1✔
50
  }
51

52
  def measure(f: => Any): Double = measure()(f)
×
53

54
  def measure(d: String)(f: => Any): Double = measure(description = d)(f)
1✔
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc