Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Test processing time (loop vs. contains)
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
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { List<String> count = new ArrayList<>(); for(int i = 1; i <= 1000000; i++) { count.add(String.valueOf(i)); } long startTime = System.currentTimeMillis(); System.out.println(count.contains("50")); long endTime = System.currentTimeMillis(); System.out.println("contain " + (endTime - startTime)); startTime = System.currentTimeMillis(); for(int i = 0;i < count.size();i++) { if(count.get(i).equals("50")) { System.out.println("true"); break; } } endTime = System.currentTimeMillis(); System.out.println("loop " + (endTime - startTime)); } }
[
+
]
Show input
Compilation time: 1.06 sec, absolute running time: 0.63 sec, cpu time: 0.8 sec, memory peak: 113 Mb, absolute service time: 1,7 sec
edit mode
|
history
|
discussion
true contain 1 true loop 0