mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Create ReadAccessor benchmark
Create a benchmark to test the performance of synthesized read accessors generated to interop with C++ [] operators.
This commit is contained in:
@@ -196,6 +196,7 @@ set(SWIFT_BENCH_MODULES
|
||||
single-source/WordCount
|
||||
single-source/XorLoop
|
||||
cxx-source/CreateObjects
|
||||
cxx-source/ReadAccessor
|
||||
)
|
||||
|
||||
set(SWIFT_MULTISOURCE_SWIFT_BENCHES
|
||||
|
||||
52
benchmark/cxx-source/ReadAccessor.swift
Normal file
52
benchmark/cxx-source/ReadAccessor.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
// Subscripts.swift - Very brief description
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2022 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
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
///
|
||||
/// This is a simple test that reads a non trivial C++ struct using an imported
|
||||
/// subscript thousands of times.
|
||||
///
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
import TestsUtils
|
||||
import CxxSubscripts
|
||||
|
||||
var vec : TwoDimensionalVector?
|
||||
|
||||
public let benchmarks = [
|
||||
BenchmarkInfo(
|
||||
name: "ReadAccessor",
|
||||
runFunction: run_ReadAccessor,
|
||||
tags: [.validation, .bridging],
|
||||
setUpFunction: {
|
||||
vec = initVector()
|
||||
})
|
||||
]
|
||||
|
||||
@inline(never)
|
||||
public func run_ReadAccessor(_ N: Int) {
|
||||
for i in 0...N {
|
||||
for j in 0..<100 {
|
||||
#if os(Linux)
|
||||
let row = vec![UInt(j)];
|
||||
#else
|
||||
let row = vec![j];
|
||||
#endif
|
||||
for k in 0..<1_000 {
|
||||
#if os(Linux)
|
||||
let element = row[UInt(k)];
|
||||
#else
|
||||
let element = row[k];
|
||||
#endif
|
||||
blackHole(element)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
benchmark/utils/CxxTests/Subscripts.h
Normal file
10
benchmark/utils/CxxTests/Subscripts.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef BENCHMARK_SUBSCRIPTS_H
|
||||
#define BENCHMARK_SUBSCRIPTS_H
|
||||
#include <vector>
|
||||
|
||||
using TwoDimensionalVector = std::vector<std::vector<int>>;
|
||||
|
||||
inline TwoDimensionalVector initVector() { return {100, std::vector<int>{1000, 0}}; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,3 +2,8 @@ module CxxCreateObjects {
|
||||
header "CreateObjects.h"
|
||||
requires cplusplus
|
||||
}
|
||||
|
||||
module CxxSubscripts {
|
||||
header "Subscripts.h"
|
||||
requires cplusplus
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ import RangeAssignment
|
||||
import RangeIteration
|
||||
import RangeOverlaps
|
||||
import RangeReplaceableCollectionPlusDefault
|
||||
import ReadAccessor
|
||||
import RecursiveOwnedParameter
|
||||
import ReduceInto
|
||||
import RemoveWhere
|
||||
@@ -332,6 +333,7 @@ register(RangeAssignment.benchmarks)
|
||||
register(RangeIteration.benchmarks)
|
||||
register(RangeOverlaps.benchmarks)
|
||||
register(RangeReplaceableCollectionPlusDefault.benchmarks)
|
||||
register(ReadAccessor.benchmarks)
|
||||
register(RecursiveOwnedParameter.benchmarks)
|
||||
register(ReduceInto.benchmarks)
|
||||
register(RemoveWhere.benchmarks)
|
||||
|
||||
Reference in New Issue
Block a user