Skip to content

Instantly share code, notes, and snippets.

View bandrzejczak's full-sized avatar

Bartek Andrzejczak bandrzejczak

View GitHub Profile
def getSongLength(
artist: Artist,
albumName: String,
songName: String): Option[Int] = {
for {
album <- artist.getAlbum(albumName)
song <- album.getSong(songName)
} yield song.getLength
}
public class ArrayListStockExchange implements StockExchange {
private List<Trade> trades = new ArrayList<>();
@Override
public void order(int ticket, int amount, int price, boolean buy) {
trades.add(new Trade(ticket, amount, price, buy));
}
@Override
class ListStockExchange : public StockExchange{
private:
std::list<Trade *> * trades;
public:
ListStockExchange() {
trades = new std::list<Trade *>();
}
Metrics Java C++
Iterations 10 10
Min. iteration time [ms] 4030.221 7890.256
Max. iteration time [ms] 9432.062 7941.776
Avg. iteration time [ms] 6251.026 7910.600
Metrics Java C++ C++ optimized
Iterations 10 10 10
Min. iteration time [ms] 4030.221 7890.256 5136.895
Max. iteration time [ms] 9432.062 7941.776 5166.630
Avg. iteration time [ms] 6251.026 7910.600 5155.023
Metrics Java C++ C++ optimized C++ off-heap
Iterations 10 10 10 10
Min. iteration time [ms] 4030.221 7890.256 5136.895 6250.862
Max. iteration time [ms] 9432.062 7941.776 5166.630 6286.141
Avg. iteration time [ms] 6251.026 7910.600 5155.023 6267.842
class ListStockExchange : public StockExchange {
private:
std::list<Trade *> * trades;
public:
ListStockExchange() {
trades = new std::list<Trade *>();
}
Metrics Java C++ C++ optimized C++ off-heap C++ combined
Iterations 10 10 10 10 10
Min. iteration time [ms] 4030.221 7890.256 5136.895 6250.862 2656.214
Max. iteration time [ms] 9432.062 7941.776 5166.630 6286.141 2665.393
Avg. iteration time [ms] 6251.026 7910.600 5155.023 6267.842 2662.243
Iteration no. Time[ms]
1 33656.406
2 16100.784
3 10734.691
4 13656.410
5 7297.651
6 7732.481
7 5081.496
8 3020.896
9 3126.210
object ScalarPuzzle extends App {
implicit class TernaryOps(cond: => Boolean) {
def ??(thenBlock: => Unit) = new {
def ::(elseBlock: => Unit): Unit =
if(cond) thenBlock else elseBlock
}
}
(1 + 1 == 2) ?? println("True") :: println("False")