Repository: dotnet/runtime
File: src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/JitInfoTests.cs (C#)

Code before:

            long square = MakeAndInvokeDynamicSquareMethod(100);
            Assert.True(square == 10000);

            TimeSpan afterCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long afterCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long afterCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsMonoAOT || PlatformDetection.IsReadyToRunCompiled)
            {
                // JitInfo metrics may be 0 in AOT scenarios
                Assert.True(beforeCompilationTime >= TimeSpan.Zero, $"Compilation time not greater or equal to 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes >= 0, $"Compiled IL bytes not greater or equal to 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount >= 0, $"Compiled method count not greater or equal to 0! ({beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(beforeCompilationTime > TimeSpan.Zero, $"Compilation time not greater than 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes > 0, $"Compiled IL bytes not greater than 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount > 0, $"Compiled method count not greater than 0! ({beforeCompiledMethodCount})");
            }

            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsBrowser)
            {
                // Before and after will most likely be the same with the interpreter and in browser because of low precision timers
                Assert.True(afterCompilationTime >= beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }
            else
            {
                Assert.True(afterCompilationTime > beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }

            if (PlatformDetection.IsMonoInterpreter)
            {
                Assert.True(afterCompiledILBytes >= beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount >= beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(afterCompiledILBytes > beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount > beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
        }


        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT), nameof(PlatformDetection.IsReflectionEmitSupported))] // JitInfo metrics will be 0 in full AOT scenarios
        public void JitInfoIsNotPopulated()
        {
            TimeSpan beforeCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long beforeCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long beforeCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

Review comment (suggestion):
```suggestion
            //
            // Mono does not include compilation of IL into interpreter byte code in there counters
            //
            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsBrowser)
```

Code after:

            long square = MakeAndInvokeDynamicSquareMethod(100);
            Assert.True(square == 10000);

            TimeSpan afterCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long afterCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long afterCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsMonoAOT || PlatformDetection.IsReadyToRunCompiled)
            {
                // JitInfo metrics may be 0 in AOT scenarios
                Assert.True(beforeCompilationTime >= TimeSpan.Zero, $"Compilation time not greater or equal to 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes >= 0, $"Compiled IL bytes not greater or equal to 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount >= 0, $"Compiled method count not greater or equal to 0! ({beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(beforeCompilationTime > TimeSpan.Zero, $"Compilation time not greater than 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes > 0, $"Compiled IL bytes not greater than 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount > 0, $"Compiled method count not greater than 0! ({beforeCompiledMethodCount})");
            }

            //
            // Mono does not include compilation of IL into interpreter byte code in these counters
            //
            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsBrowser)
            {
                // Before and after can be same in browser because of low precision timers
                Assert.True(afterCompilationTime >= beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }
            else
            {
                Assert.True(afterCompilationTime > beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }

            if (PlatformDetection.IsMonoInterpreter)
            {
                Assert.True(afterCompiledILBytes >= beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount >= beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(afterCompiledILBytes > beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount > beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
        }


        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT), nameof(PlatformDetection.IsReflectionEmitSupported))] // JitInfo metrics will be 0 in full AOT scenarios
        public void JitInfoIsNotPopulated()
        {