Skip to content

Instantly share code, notes, and snippets.

View amaembo's full-sized avatar

Tagir Valeev amaembo

View GitHub Profile
import org.openjdk.jmh.annotations.*;
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@amaembo
amaembo / MethodCallTest.java
Last active December 25, 2016 14:55
sun.reflect.noInflation makes code faster?
import org.openjdk.jmh.annotations.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
@Fork(3)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@amaembo
amaembo / Test.java
Created February 11, 2017 15:26
An addition to http://stackoverflow.com/a/42176321/4856258 (using StreamEx)
import one.util.streamex.EntryStream;
import one.util.streamex.StreamEx;
import java.util.*;
public class Test {
static List<List<Integer>> mergeCollections(List<List<Integer>> input) {
return StreamEx.of(input).foldLeft(Collections.emptyList(),
(List<List<Integer>> acc, List<Integer> listInner) -> EntryStream
.of(StreamEx.of(acc).partitioningBy(list -> list.stream().anyMatch(listInner::contains)))
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.*;
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@amaembo
amaembo / February31.java
Created February 6, 2018 02:50
BlackboxA
import java.util.*;
public class February31 {
private static final int[] kDaysInMonth = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
boolean ValidateDateTime(DateTime time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
@amaembo
amaembo / February31.java
Created February 6, 2018 02:51
BlackboxB
public class February31 {
public static final int[] kDaysInMonth = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
boolean ValidateDateTime(DateTime time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
package com.example;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.concurrent.*;import java.util.function.Supplier;import java.util.stream.Collectors;import java.util.stream.IntStream;
@Fork(3)
@Warmup(iterations=10, time=500, timeUnit=TimeUnit.MILLISECONDS)
@Measurement(iterations=10, time=500, timeUnit=TimeUnit.MILLISECONDS)
@amaembo
amaembo / keybase.md
Created January 23, 2020 09:09
keybase.md

Keybase proof

I hereby claim:

  • I am amaembo on github.
  • I am tagir_valeev (https://keybase.io/tagir_valeev) on keybase.
  • I have a public key ASCH6kfJO8v94QIiMxjf6F-9bUZjiAGg5eoDfSUshwFNmAo

To claim this, I am signing this object:

@amaembo
amaembo / BenchmarkStreamConcat.java
Created March 31, 2020 03:06
Stream.concat vs StreamEx
package com.soebes.performance.streams;
import org.openjdk.jmh.annotations.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.concurrent.TimeUnit;
public class AbstractEnumConverter<T extends Enum<T>> {
private final Class<T> enumClass;
private final T[] values;
protected AbstractEnumConverter(Class<T> enumClass) {
assert enumClass.isEnum();
this.enumClass = enumClass;
this.values = enumClass.getEnumConstants();