Skip to content

Instantly share code, notes, and snippets.

@jcsahnwaldt
jcsahnwaldt / ToMap.java
Last active August 29, 2015 14:16
Microbenchmark: Convert list to map with or without streams / lambdas. Result: Performance is the same. See https://stackoverflow.com/questions/674639/scala-best-way-of-turning-a-collection-into-a-map-by-key/3249462#comment46124673_3249462
import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;
import java.util.function.*;
class Value {
private final String key;
public Value(String key) {
@jcsahnwaldt
jcsahnwaldt / ProcFunc.java
Created March 10, 2015 04:38
Microbenchmark: procedural vs functional extraction of error lines. See https://twitter.com/jcsahnwaldt/status/574705132555923456
import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;
import java.io.*;
import java.nio.file.*;
public class ProcFunc {
public static <T> Iterator<T> limit(Iterator<? extends T> it, int max) {
return new Iterator<T>() {
// https://stackoverflow.com/questions/53585022/three-colors-triangles/53588144#53588144
// https://www.codewars.com/kata/insane-coloured-triangles/train/c
#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
char triangle(const char *s)
{
char* row = strdup(s);
# Results in comments are from Ruby 3.2.2, libxml-ruby 4.1.1 on macOS
require 'libxml-ruby'
# new() is undefined for Writer
# https://github.com/xml4r/libxml-ruby/blob/master/ext/libxml/ruby_xml_writer.c#L1134
# LibXML::XML::Writer.new() # crash: undefined method `new' for LibXML::XML::Writer:Class (NoMethodError)
LibXML::XML::Writer.io(nil) # warning: undefining the allocator of T_DATA class LibXML::XML::Writer
# new() is neither undefined nor redefined for Reader
#include <stdio.h>
#include <math.h>
#define MAX 100
static int memo[MAX+1];
static int partitions(int n) {
int p = memo[n];
if (p != 0) return p;