mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
DigestUtil: add performance test.
GitOrigin-RevId: 72a2e9854041554ebb4f944323407614dedbea3a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3a0236ddd8
commit
027ad26f17
@@ -0,0 +1,35 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing
|
||||
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.intellij.util.io.DigestUtil
|
||||
import org.apache.commons.lang.RandomStringUtils
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class DigestUtilTest {
|
||||
|
||||
private val digest = DigestUtil.sha1()
|
||||
|
||||
@Test
|
||||
fun `digest evaluation performance test`() {
|
||||
val stringsNumber = 1000
|
||||
val stringLength = 10000
|
||||
val randomBytes = (0 until stringsNumber)
|
||||
.map { RandomStringUtils.random(stringLength) }
|
||||
.map { it.toByteArray() }
|
||||
|
||||
val threadPool = Executors.newFixedThreadPool(8)
|
||||
val callableList = randomBytes.map { Callable { calculateContentHash(it) } }
|
||||
|
||||
PlatformTestUtil.startPerformanceTest("DigestUtil works quickly enough", 250) {
|
||||
threadPool.invokeAll(callableList)
|
||||
}.usesAllCPUCores().attempts(5).assertTiming()
|
||||
}
|
||||
|
||||
private fun calculateContentHash(bytes: ByteArray) {
|
||||
DigestUtil.calculateContentHash(digest, bytes)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user