# Why "manual" batching is faster than using inputBuffer

**URL:** <https://discuss.akka.io/t/why-manual-batching-is-faster-than-using-inputbuffer/8211>\
**Category:** Akka Streams & Alpakka\
**Created:** [May 6, 2021, 1:24pm UTC](https://discuss.akka.io/t/why-manual-batching-is-faster-than-using-inputbuffer/8211 "2021-05-06T13:24:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dssysolyatin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/dssysolyatin/32/2353_2.png) [@dssysolyatin](https://discuss.akka.io/u/dssysolyatin)\
**Post date:** [May 6, 2021, 1:24pm UTC](https://discuss.akka.io/t/why-manual-batching-is-faster-than-using-inputbuffer/8211/1 "2021-05-06T13:24:40Z")

</div>

Hi,  
I am doing experiments with async + inputBuffers and I can not understand why “manual” batching is faster than using inputBuffer attribute (in my laptop in five times faster). Can someone explain ?

Code:

```auto
import akka.actor.ActorSystem
import akka.stream.Attributes
import akka.stream.scaladsl.{Sink, Source}

import scala.concurrent.Await
import scala.concurrent.duration.Duration

object TimedUtil {
  def timed[T](prefix: String)(cmd: => T): T = {
    val t0 = System.currentTimeMillis()
    val res = cmd
    println(s"duration of $prefix: ${System.currentTimeMillis() - t0}")
    res
  }
}

object Async extends App {
  implicit val system = ActorSystem()
  val numberOfIterations = 10000000

  TimedUtil.timed("async") {
    val source = Source
      .fromIterator(() => (0 to numberOfIterations).iterator)
      .async
      .withAttributes(Attributes.inputBuffer(1024, 1024))
      .map(a => a + 1)
      .runWith(Sink.ignore)

    Await.result(source, Duration.Inf)
  }

  TimedUtil.timed("async-batch") {
    val source = Source
      .fromIterator(() => (0 to numberOfIterations).iterator)
      .batch(1024, el => Vector.newBuilder += el)({ (acc, el) =>
        acc += el
      })
      .map(_.result())
      .async
      .mapConcat(identity)
      .map(a => a + 1)
      .runWith(Sink.ignore)

    Await.result(source, Duration.Inf)
  }

  system.terminate()
}

```
