Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
compile c++ clang online
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#include <iostream> #include <vector> #include <random> #include <chrono> #include <algorithm> struct A { A(int i = 0) : i(i) {} int i; static int nSwaps; friend void swap(A& l, A& r) { ++nSwaps; std::swap(l.i, r.i); } bool operator<(const A& r) const { return i < r.i; } }; int A::nSwaps = 0; using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::milliseconds; int main() { std::vector<A> v(10000000); std::minstd_rand gen(std::random_device{}()); std::generate(v.begin(), v.end(), [&gen]() {return gen();}); auto s = high_resolution_clock::now(); std::sort(v.begin(), v.end()); std::cout << duration_cast<milliseconds>(high_resolution_clock::now() - s).count() << "ms with " << A::nSwaps << " swaps\n"; A::nSwaps = 0; s = high_resolution_clock::now(); std::shuffle(v.begin(), v.end(), gen); std::cout << duration_cast<milliseconds>(high_resolution_clock::now() - s).count() << "ms with " << A::nSwaps << " swaps\n"; }
clang++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.83 sec, absolute running time: 1.64 sec, cpu time: 1.57 sec, memory peak: 40 Mb, absolute service time: 2.48 sec
edit mode
|
history
866ms with 47531999 swaps 640ms with 9999999 swaps