나는 scalaz-streams sink에 관한 이상한 관찰을 가지고있다. 그들은 천천히 일하고 있습니다. 아무도 왜 그런지 압니까? 그리고 성능을 향상시킬 수있는 방법이 있습니까? 7S이 하나가 실행 33 개의 초 정도 걸립니다싱크대의 코드 성능을 향상시키는 방법은 무엇입니까?
//p is the same as before
def printToImage(img: BufferedImage)(pixel: Pixel): Unit = {
img.setRGB(pixel.x, pixel.y, 1, 1, Array(pixel.rgb), 0, 0)
}
//I've found that way of doing sink in some tutorial
def getImageSink(img: BufferedImage): Sink[Task, Pixel] = {
//I've tried here Task.delay and Task.now with the same results
def printToImageTask(img: BufferedImage)(pixel: Pixel): Task[Unit] = Task.delay {
printToImage(img)(pixel)
}
Process.constant(printToImageTask(img))
}
val image = getBlankImage(2000, 4000)
val result = p.to(getImageSink(image)).run.run
싱크
버전을 실행하는 데 ~이 소요
//p is parameter with type p: Process[Task, Pixel]
def printToImage(img: BufferedImage)(pixel: Pixel): Unit = {
img.setRGB(pixel.x, pixel.y, 1, 1, Array(pixel.rgb), 0, 0)
}
val image = getBlankImage(2000, 4000)
val result = p.runLog.run
result.foreach(printToImage(image))
싱크없이 버전 : 여기
내 코드의 관련 부분입니다 . 나는 그 중요한 차이 때문에 여기에서 완전히 혼란 스럽다.
감사합니다. 그 이상한 행동을 설명합니다. 나는 이것이 경량의 공정이라고 생각했다. – user2963977