Skip to content

Instantly share code, notes, and snippets.

@jshvarts
jshvarts / currentTimeMillis.java
Created June 27, 2017 05:05
currentTimeMillis way in Java
long startTime = System.currentTimeMillis();
// some code block here
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Execution took (in millis): " + elapsedTime);
@jshvarts
jshvarts / measureTimeMillis.kt
Created June 27, 2017 05:08
measureTimeMillis Kotlin
val timeElapsed = measureTimeMillis {
// some code block
}
println("$timeElapsed")
@jshvarts
jshvarts / measureTimeMillis_for_loop.kt
Created June 27, 2017 05:12
measureTimeMillis of for loop
val forLoopMillisElapsed = measureTimeMillis {
for (i in 0..10_000_000) {
if (i % 2 == 0) {
// do something
}
}
}
println("forLoopMillisElapsed: $forLoopMillisElapsed")
@jshvarts
jshvarts / measureTimeMillis_forEach.kt
Created June 27, 2017 05:13
measureTimeMillis of forEach
val forEachMillisEllapsed = measureTimeMillis {
(0..10_000_000).forEach {
if (it % 2 == 0) {
// do something
}
}
}
println("forEachMillisEllapsed: $forEachMillisEllapsed")
@jshvarts
jshvarts / for_loop_decompiled.java
Created June 27, 2017 05:18
For loop decompiled
i = 0;
int var8 = 10000000;
if(i <= var8) {
while(true) {
if(i % 2 == 0) {
var10000 = true;
} else {
var10000 = false;
}
@jshvarts
jshvarts / forEach_decompiled.java
Created June 27, 2017 05:20
forEach decompiled contains Iterator
Iterable $receiver$iv = (Iterable)(new IntRange(0, 10000000));
Iterator var6 = $receiver$iv.iterator();
boolean var10000;
int i;
while(var6.hasNext()) {
i = ((IntIterator)var6).nextInt();
if(i % 2 == 0) {
var10000 = true;
} else {
public class ViewModelDemoActivity extends LifecycleActivity {
@BindView(R.id.click_count_text)
protected TextView clickCountText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewmodel_demo);
ButterKnife.bind(this);
public class DemoActivity extends AppCompatActivity {
@BindView(R.id.click_count_text)
protected TextView clickCountText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewmodel_demo);
ButterKnife.bind(this);
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
import android.arch.lifecycle.ViewModel;
public class ClickCounterViewModel extends ViewModel {
private int count;
public void setCount(int count) {
this.count = count;
}
public int getCount() {