Skip to content

Instantly share code, notes, and snippets.

@SystemFw
SystemFw / Fib.scala
Last active December 19, 2023 19:38
Deriving tail recursive Fibonacci
/*
Here's a derivation for a tail recursive fibonacci function.
Let's start from the Maths definition:
fib(0) = 0
fib(1) = 1
fib(n) = fib(n - 1) + fib(n - 2)
*/
// Let's translate the structure, leaving the recursive case unspecified:
@ChristopherDavenport
ChristopherDavenport / Libraries.md
Last active February 1, 2024 11:38
A Current Listing of Libraries
@dacr
dacr / gatling-simple.sc
Last active April 2, 2023 10:12
Just ONE ammonite script file to execute a load performance test using gatling ! / published by https://github.com/dacr/code-examples-manager #ea7a4259-9461-44a8-99fa-1ec6ec3c48ed/6bc5335f1571c83edc6278c55499c9c7ae43a5c0
// summary : Just ONE ammonite script file to execute a load performance test using gatling !
// keywords : scala, gatling, ammonite, scala, load-test, performance
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed
// created-on : 2018-09-22T07:41:07Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@Sloy
Sloy / MockParcel.java
Created February 26, 2015 12:50
MockParcel for testing Parcelables implementations with the new Android's Unit testing support (http://tools.android.com/tech-docs/unit-testing-support). Only String and Long read/write implemented here. Add mock methods for other types.
import android.os.Parcel;
import java.util.ArrayList;
import java.util.List;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;