<commit_before>//===--- IndexPathTest.swift ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import TestsUtils
import Foundation

let size = 200
let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]

public let IndexPathTest = [
  BenchmarkInfo(name: "IndexPathSubscriptMutation", 
  runFunction: { n in run_IndexPathSubscriptMutation(n * 1000, size)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathSubscriptRangeMutation", 
  runFunction: { n in run_IndexPathSubscriptRangeMutation(n * 1000, size)}, 
  tags: tags),

  BenchmarkInfo(name: "IndexPathMaxBeginning", 
  runFunction: { n in run_IndexPathMaxBeginning(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMaxMiddle", 
  runFunction: { n in run_IndexPathMaxMiddle(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMaxEnd", 
  runFunction: { n in run_IndexPathMaxEnd(n * 1000)}, 
  tags: tags),

  BenchmarkInfo(name: "IndexPathMinBeginning", 
  runFunction: { n in run_IndexPathMinBeginning(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMinMiddle", 
  runFunction: { n in run_IndexPathMinMiddle(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMinEnd", 
  runFunction: { n in run_IndexPathMinEnd(n * 1000)}, 
  tags: tags),
]

@inline(__always)
func indexPath(_ size: Int, reversed: Bool = false) -> IndexPath {
    let indexes = Array(0..<size)
    return IndexPath(indexes: reversed ? indexes.reversed() : indexes)
}

@inline(__always)
func indexPath(_ size: Int, middle: Int) -> IndexPath {
    var indexes = Array(0..<size)
    indexes.insert(middle, at: (indexes.count - 1) / 2)
    return IndexPath(indexes: indexes)
}

// Subscript Mutations

@inline(__always)
func subscriptMutation(n: Int,
  mutations: Int,
  mutate: (inout IndexPath, Int) -> ()) {
    for _ in 0..<n {
      var ip = indexPath(size)

      for i in 0..<mutations {
        mutate(&ip, i)
      }

      blackHole(ip)
    }
}

@inline(never)
public func run_IndexPathSubscriptMutation(_ n: Int, _ count: Int) {
  subscriptMutation(n: n,  mutations: count, mutate: { ip, i in
		ip[i % 4] += 1
	})
}

@inline(never)
public func run_IndexPathSubscriptRangeMutation(_ n: Int, _ count: Int) {
  subscriptMutation(n: count, mutations: count, mutate: { ip, i in
		ip[0..<i] += [i]
	})
}

// Max, Min

@inline(__always)
func maxMin(n: Int, 
  creator: () -> IndexPath, 
  maxMinFunc: (inout IndexPath) -> Int?) {
    for _ in 0..<n {
      var ip = creator()
      let found = maxMinFunc(&ip) != nil
      blackHole(found)
    }
}

// Max

@inline(never)
public func run_IndexPathMaxBeginning(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, reversed: true)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

@inline(never)
public func run_IndexPathMaxMiddle(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, middle: size + 1)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

@inline(never)
public func run_IndexPathMaxEnd(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

// Min

@inline(never)
public func run_IndexPathMinBeginning(_ n: Int) {
  maxMin(n: n, creator: {
   indexPath(size)
  }, maxMinFunc: { ip in
    ip.min()
  })
}

@inline(never)
public func run_IndexPathMinMiddle(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, middle: -1)
  }, maxMinFunc: { ip in
    ip.min()
  })
}

@inline(never)
public func run_IndexPathMinEnd(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, reversed: true)
  }, maxMinFunc: { ip in
    ip.min()
  })
}<commit_msg>Fix indentation, move params to new line<commit_after>//===--- IndexPathTest.swift ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import TestsUtils
import Foundation

let size = 200
let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]

public let IndexPathTest = [
  BenchmarkInfo(name: "IndexPathSubscriptMutation", 
  runFunction: { n in run_IndexPathSubscriptMutation(n * 1000, size)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathSubscriptRangeMutation", 
  runFunction: { n in run_IndexPathSubscriptRangeMutation(n * 1000, size)}, 
  tags: tags),

  BenchmarkInfo(name: "IndexPathMaxBeginning", 
  runFunction: { n in run_IndexPathMaxBeginning(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMaxMiddle", 
  runFunction: { n in run_IndexPathMaxMiddle(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMaxEnd", 
  runFunction: { n in run_IndexPathMaxEnd(n * 1000)}, 
  tags: tags),

  BenchmarkInfo(name: "IndexPathMinBeginning", 
  runFunction: { n in run_IndexPathMinBeginning(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMinMiddle", 
  runFunction: { n in run_IndexPathMinMiddle(n * 1000)}, 
  tags: tags),
  BenchmarkInfo(name: "IndexPathMinEnd", 
  runFunction: { n in run_IndexPathMinEnd(n * 1000)}, 
  tags: tags),
]

@inline(__always)
func indexPath(_ size: Int, reversed: Bool = false) -> IndexPath {
    let indexes = Array(0..<size)
    return IndexPath(indexes: reversed ? indexes.reversed() : indexes)
}

@inline(__always)
func indexPath(_ size: Int, middle: Int) -> IndexPath {
    var indexes = Array(0..<size)
    indexes.insert(middle, at: (indexes.count - 1) / 2)
    return IndexPath(indexes: indexes)
}

// Subscript Mutations

@inline(__always)
func subscriptMutation(
  n: Int,
  mutations: Int,
  mutate: (inout IndexPath, Int) -> ()) {
    for _ in 0..<n {
      var ip = indexPath(size)

      for i in 0..<mutations {
        mutate(&ip, i)
      }

      blackHole(ip)
    }
}

@inline(never)
public func run_IndexPathSubscriptMutation(_ n: Int, _ count: Int) {
  subscriptMutation(n: n,  mutations: count, mutate: { ip, i in
		ip[i % 4] += 1
  })
}

@inline(never)
public func run_IndexPathSubscriptRangeMutation(_ n: Int, _ count: Int) {
  subscriptMutation(n: count, mutations: count, mutate: { ip, i in
		ip[0..<i] += [i]
  })
}

// Max, Min

@inline(__always)
func maxMin(
  n: Int, 
  creator: () -> IndexPath, 
  maxMinFunc: (inout IndexPath) -> Int?) {
    for _ in 0..<n {
      var ip = creator()
      let found = maxMinFunc(&ip) != nil
      blackHole(found)
    }
}

// Max

@inline(never)
public func run_IndexPathMaxBeginning(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, reversed: true)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

@inline(never)
public func run_IndexPathMaxMiddle(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, middle: size + 1)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

@inline(never)
public func run_IndexPathMaxEnd(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size)
  }, maxMinFunc: { ip in
    ip.max()
  })
}

// Min

@inline(never)
public func run_IndexPathMinBeginning(_ n: Int) {
  maxMin(n: n, creator: {
   indexPath(size)
  }, maxMinFunc: { ip in
    ip.min()
  })
}

@inline(never)
public func run_IndexPathMinMiddle(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, middle: -1)
  }, maxMinFunc: { ip in
    ip.min()
  })
}

@inline(never)
public func run_IndexPathMinEnd(_ n: Int) {
  maxMin(n: n, creator: {
    indexPath(size, reversed: true)
  }, maxMinFunc: { ip in
    ip.min()
  })
}
{'fraction_non_alphanumeric': 0.16723206432968965, 'fraction_numerical': 0.013318256062319386, 'mean_word_length': 3.1697223677317967, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '7578525', 'n_tokens_mistral': 2933, 'n_tokens_neox': 2741, 'n_words': 712}