<commit_before>//===--- DataBenchmarks.swift ---------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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 d: [BenchmarkCategory] =  [.validation, .api, .Data]

/// Workload scaling: Inner loop multipliers
let M = 10_000  /// default
let I = 100_000 /// Data initialization
let S = 200     /// String conversions

public let DataBenchmarks = [
  BenchmarkInfo(name: "DataCreateEmpty",
    runFunction: { for _ in 0..<$0*I/10 { blackHole(Data()) } },
    tags: d, legacyFactor: 10),
  BenchmarkInfo(name: "DataCreateSmall",
    runFunction: { for _ in 0..<$0*I/1000 { blackHole(sampleData(.small)) } },
    tags: d, legacyFactor: 1000),
  BenchmarkInfo(name: "DataCreateMedium",
    runFunction: { for _ in 0..<$0*M/100 { blackHole(sampleData(.medium)) } },
    tags: d, legacyFactor: 100),

  BenchmarkInfo(name: "DataCreateEmptyArray",
    runFunction: { for _ in 0..<$0*I/50 { blackHole(Data([])) } }, tags: d,
    legacyFactor: 50),
  BenchmarkInfo(name: "DataCreateSmallArray",
    runFunction: { for _ in 0..<$0*I/50 { blackHole(Data(
      [0, 1, 2, 3, 4, 5, 6])) } }, tags: d, legacyFactor: 50),
  BenchmarkInfo(name: "DataCreateMediumArray",
    runFunction: { for _ in 0..<$0*M/20 { blackHole(Data([
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
    ])) } }, tags: d, legacyFactor: 20),

  BenchmarkInfo(name: "DataSubscriptSmall",
    runFunction: { for _ in 0..<$0*M { blackHole(small[1]) } }, tags: d),
  BenchmarkInfo(name: "DataSubscriptMedium",
    runFunction: { for _ in 0..<$0*M { blackHole(medium[521]) } }, tags: d),

  BenchmarkInfo(name: "DataCountSmall",
    runFunction: { count($0*M, data: small) }, tags: d),<commit_msg>[benchmark] Fix DataSubscript fragile inlining?<commit_after>//===--- DataBenchmarks.swift ---------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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 d: [BenchmarkCategory] =  [.validation, .api, .Data]

/// Workload scaling: Inner loop multipliers
let M = 10_000  /// default
let I = 100_000 /// Data initialization
let S = 200     /// String conversions

public let DataBenchmarks = [
  BenchmarkInfo(name: "DataCreateEmpty",
    runFunction: { for _ in 0..<$0*I/10 { blackHole(Data()) } },
    tags: d, legacyFactor: 10),
  BenchmarkInfo(name: "DataCreateSmall",
    runFunction: { for _ in 0..<$0*I/1000 { blackHole(sampleData(.small)) } },
    tags: d, legacyFactor: 1000),
  BenchmarkInfo(name: "DataCreateMedium",
    runFunction: { for _ in 0..<$0*M/100 { blackHole(sampleData(.medium)) } },
    tags: d, legacyFactor: 100),

  BenchmarkInfo(name: "DataCreateEmptyArray",
    runFunction: { for _ in 0..<$0*I/50 { blackHole(Data([])) } }, tags: d,
    legacyFactor: 50),
  BenchmarkInfo(name: "DataCreateSmallArray",
    runFunction: { for _ in 0..<$0*I/50 { blackHole(Data(
      [0, 1, 2, 3, 4, 5, 6])) } }, tags: d, legacyFactor: 50),
  BenchmarkInfo(name: "DataCreateMediumArray",
    runFunction: { for _ in 0..<$0*M/20 { blackHole(Data([
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
      0, 1, 2, 3, 4, 5, 6,
    ])) } }, tags: d, legacyFactor: 20),

  BenchmarkInfo(name: "DataSubscriptSmall",
    runFunction: { let data = small
      for _ in 0..<$0*M { blackHole(data[1]) } }, tags: d),
  BenchmarkInfo(name: "DataSubscriptMedium",
    runFunction: { let data = medium
      for _ in 0..<$0*M { blackHole(data[521]) } }, tags: d),

  BenchmarkInfo(name: "DataCountSmall",
    runFunction: { count($0*M, data: small) }, tags: d),
{'fraction_non_alphanumeric': 0.21277075812274368, 'fraction_numerical': 0.04963898916967509, 'mean_word_length': 2.7096234309623433, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, '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': '5001940', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1476, 'n_words': 421}