Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
csharp source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
.NET (main)
.NET (main) CoreCLR
.NET (main) Crossgen2
.NET (main) ILDasm
.NET (main) ILSpy
.NET (main) Mono
.NET (main) NativeAOT
.NET 6.0 CoreCLR
.NET 6.0 Crossgen2
.NET 6.0 ILDasm
.NET 6.0 ILSpy
.NET 6.0 Mono
.NET 6.0.110
.NET 6.0.113
.NET 6.0.116
.NET 7.0 CoreCLR
.NET 7.0 Crossgen2
.NET 7.0 ILDasm
.NET 7.0 ILSpy
.NET 7.0 Mono
.NET 7.0.100
.NET 7.0.102
.NET 7.0.105
.NET 8.0 CoreCLR
.NET 8.0 Crossgen2
.NET 8.0 ILDasm
.NET 8.0 ILSpy
.NET 8.0 Mono
.NET 9.0 CoreCLR
.NET 9.0 Crossgen2
.NET 9.0 ILDasm
.NET 9.0 ILSpy
.NET 9.0 Mono
Options
Source code
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Xml.Linq; namespace LINQtest { public static class Settings { public const int VECTORSIZE = 12800000;//640000; } class Element : IComparable<Element> { private int tag; private int order; private int data; public Element(int t, int o, int d) { tag = t; order = o; data = d; } public Element(int idx) { tag=idx % 8; order=idx % 12; data=idx; } public int Tag { get => tag; set => tag = value; } public int Order { get => order; set => order = value; } public int Data { get => data; set => data = value; } public int CompareTo(Element? b) => b == null ? 1 : (b.order * Settings.VECTORSIZE + b.data) - (order * Settings.VECTORSIZE + data); public bool ZeroTag => tag == 0; public int Cal => Order * Settings.VECTORSIZE + Data; } class Program { static void checkResults(IEnumerable<Element> resultVector) { int d = 0; int o = 0; foreach (var element in resultVector) { if (d > element.Data && o > element.Order) throw new Exception("Ordering failed"); d = element.Data; o = element.Order; } } static void testClasic(IReadOnlyList<Element> testVector, bool order, int run) { Stopwatch sw = new(); sw.Start(); var resultVector = new List<Element>(testVector.Count / 8); foreach (var element in testVector) { if (element.ZeroTag) resultVector.Add(element); } if (order) resultVector.Sort(); if (resultVector.Count != Settings.VECTORSIZE / 8) throw new Exception("Number of result elements not correct!"); checkResults(resultVector); sw.Stop(); Console.WriteLine( "Classic ({0}), run {1} -> Time: {2} sec To be: {3} Result: {4}", (order ? "ordered" : "not ordered"), run, sw.Elapsed.ToString().Substring(7), Settings.VECTORSIZE / 8, resultVector.Count()); } static void testLINQ(IReadOnlyList<Element> testVector, bool order, int run) { Stopwatch sw = new Stopwatch(); sw.Start(); List<Element> resultVector = (order ? testVector.Where(element => element.ZeroTag) .OrderBy(element => element.Cal) : testVector.Where(element => element.ZeroTag)).ToList(); if (resultVector.Count() != Settings.VECTORSIZE / 8) throw new Exception("Number of result elements not correct!"); checkResults(resultVector); sw.Stop(); Console.WriteLine( "LINQ ({0}), run {1} -> Time: {2} sec To be: {3} Result: {4}", (order ? "ordered" : "not ordered"), run, sw.Elapsed.ToString().Substring(7), Settings.VECTORSIZE / 8, resultVector.Count()); } static void Main(string[] args) { var testVector = new List<Element>(Settings.VECTORSIZE); for (int index = 0; index < Settings.VECTORSIZE; index++) testVector.Add(new(index)); for (int run = 0; run < 4; run++) { testLINQ(testVector, false, run); testClasic(testVector, false, run); } for (int run = 0; run < 4; run++) { testLINQ(testVector, true, run); testClasic(testVector, true, run); } // var key = Console.ReadKey(); } } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree