1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import * as all from "std/math"; 17 18/** 19 * @State 20 * @Bugs 0000 21 * @Tags common 22 */ 23export class ArraySort { 24 /** 25 * @Param 100 26 */ 27 size: int; 28 29 /** 30 * Specifics of the array to be sorted. 31 * @Param "sorted", "sorted_reversed" 32 */ 33 distribution: String; 34 35 ints: int[]; 36 intsInitial: int[]; 37 38 /** 39 * Prepare array depending on the distribution variant. 40 * @Setup 41 */ 42 public prepareArray(): void { 43 this.ints = new int[this.size]; 44 this.intsInitial = new int[this.size]; 45 switch (this.distribution) { 46 case "sorted": 47 for (let i = 0; i < this.size; i++) { 48 this.intsInitial[i] = i; 49 } 50 break; 51 case "sorted_reversed": 52 for (let i = 0; i < this.size; i++) { 53 this.intsInitial[i] = this.size - i; 54 } 55 break; 56 default: 57 break; 58 } 59 } 60 61 /** 62 * @Benchmark 63 * @Bugs sortbug 64 * @Tags sorttag 65 */ 66 public sort(): void throws { 67 copyTo(this.intsInitial, this.ints, 0, 0, this.size); 68 sort(this.ints); 69 } 70 71 /** 72 * @Benchmark -wi 0 -mi 1 73 */ 74 public baseline(): void throws { 75 copyTo(this.intsInitial, this.ints, 0, 0, this.size); 76 } 77} 78