<commit_before>package fs2
package benchmark

import fs2.util._

import org.openjdk.jmh.annotations.{Benchmark, State, Scope}

@State(Scope.Thread)
class TaskBenchmark {

  val range = 1 to 1000000

  def sum(start: Int, end: Int): Int = {
    var i = start
    var sum = 0

    while(i < end) {
      i += 1
      sum += i
	}
    sum
  }

  def taskSum(implicit S: Strategy): Task[Int] = Task(sum(range.start, range.end))

  //to compare with
  @Benchmark
  def sumCurrentThread: Int = {
    sum(range.start, range.end)
  }

  @Benchmark
  def sumSingleThread: Int = {
   implicit val S: Strategy = Strategy.fromFixedDaemonPool(1)
   taskSum.unsafeRun
  }

  @Benchmark
  def sumMultiThread: Int = {
    implicit val S: Strategy = Strategy.fromFixedDaemonPool(4)
    (for {
      t1 <- Task.start { taskSum }
      t2 <- Task.start{ taskSum }
      t3 <- Task.start { taskSum }<commit_msg>don't be a twit and measure the correct thing<commit_after>package fs2
package benchmark

import fs2.util._

import org.openjdk.jmh.annotations.{Benchmark, State, Scope}

@State(Scope.Thread)
class TaskBenchmark {

  val range = 1 to 1000000

  def sum(start: Int, end: Int): Int = {
    var i = start
    var sum = 0

    while(i < end) {
      i += 1
      sum += i
	}
    sum
  }

  def taskSum(implicit S: Strategy): Task[Int] = Task(sum(range.start, range.end))

  //to compare with
  @Benchmark
  def sumCurrentThread: Int = {
    sum(range.start, range.end)
  }
  
  val singleThreadedStrategy = Strategy.fromFixedDaemonPool(1)

  @Benchmark
  def sumSingleThread: Int = {
   implicit val S: Strategy = singleThreadedStrategy
   taskSum.unsafeRun
  }
  
  val multiThreadedStrategy = Strategy.fromFixedDaemonPool(4)
  
  @Benchmark
  def sumMultiThread: Int = {
	//This needs to be removed
    implicit val S: Strategy = multiThreadedStrategy
    (for {
      t1 <- Task.start { taskSum }
      t2 <- Task.start{ taskSum }
      t3 <- Task.start { taskSum }
{'fraction_non_alphanumeric': 0.10696008188331628, 'fraction_numerical': 0.017400204708290685, 'mean_word_length': 2.8408644400785854, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '978094', 'n_tokens_mistral': 727, 'n_tokens_neox': 674, 'n_words': 183}