|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2016-2025 Objectionary.com |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included |
| 14 | + * in all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +package benchmarks; |
| 25 | + |
| 26 | +import com.jcabi.xml.XML; |
| 27 | +import com.jcabi.xml.XMLDocument; |
| 28 | +import fixtures.LargeXmir; |
| 29 | +import java.util.concurrent.TimeUnit; |
| 30 | +import org.cactoos.scalar.Unchecked; |
| 31 | +import org.eolang.lints.Program; |
| 32 | +import org.openjdk.jmh.annotations.Benchmark; |
| 33 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 34 | +import org.openjdk.jmh.annotations.Fork; |
| 35 | +import org.openjdk.jmh.annotations.Measurement; |
| 36 | +import org.openjdk.jmh.annotations.Mode; |
| 37 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 38 | +import org.openjdk.jmh.annotations.Scope; |
| 39 | +import org.openjdk.jmh.annotations.State; |
| 40 | +import org.openjdk.jmh.annotations.Warmup; |
| 41 | + |
| 42 | +/** |
| 43 | + * Benchmark for {@link Program}. |
| 44 | + * |
| 45 | + * @since 0.0.34 |
| 46 | + * @checkstyle DesignForExtensionCheck (10 lines) |
| 47 | + * @checkstyle NonStaticMethodCheck (100 lines) |
| 48 | + */ |
| 49 | +@Fork(1) |
| 50 | +@BenchmarkMode(Mode.AverageTime) |
| 51 | +@OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 52 | +@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS) |
| 53 | +@Measurement(iterations = 2, time = 1, timeUnit = TimeUnit.MILLISECONDS) |
| 54 | +@State(Scope.Benchmark) |
| 55 | +public class ProgramBench { |
| 56 | + |
| 57 | + /** |
| 58 | + * Large XMIR document. |
| 59 | + */ |
| 60 | + private static final XML LARGE = new Unchecked<>(new LargeXmir()).value(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Small XMIR document. |
| 64 | + */ |
| 65 | + private static final XML SMALL = new XMLDocument("<program name='foo'/>"); |
| 66 | + |
| 67 | + @Benchmark |
| 68 | + public final void scansLargeXmir() { |
| 69 | + new Program(ProgramBench.LARGE).defects(); |
| 70 | + } |
| 71 | + |
| 72 | + @Benchmark |
| 73 | + public final void scansSmallXmir() { |
| 74 | + new Program(ProgramBench.SMALL).defects(); |
| 75 | + } |
| 76 | +} |
0 commit comments