Skip to content

Instantly share code, notes, and snippets.

@firejox
firejox / bench.cr
Created October 14, 2019 05:31
Channel select unwait benchmark
ch1 = Channel(Int32).new
ch2 = Channel(Int32).new
500.times do
spawn do
r = Random.new
ch2.send(r.next_int)
end
end
@firejox
firejox / static_list.cr
Created October 7, 2019 16:57
Circular Linked List
macro container_of(ptr, _type, member)
{% if _type.resolve < Reference %}
(({{ ptr }}).as(Void*) - offsetof({{ _type }}, {{ member }})).as({{ _type }})
{% else %}
(({{ ptr }}).as(Void*) - offsetof({{ _type }}, {{ member }})).as(Pointer({{ _type }}))
{% end %}
end
struct StaticList
@prev = uninitialized Pointer(StaticList)
@firejox
firejox / lscpu
Last active September 25, 2019 07:21
fiber context switch benchmark
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 48 bits physical, 48 bits virtual
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
#ifndef FIBFUZZYSHELLSORT_HPP
#define FIBFUZZYSHELLSORT_HPP
#include <limits>
#include "ShellSortTemplate.hpp"
#include "IntegralConstantArithmetic.hpp"
namespace FibFuzzyNS {
using namespace IntegralConstantArithmetic;
@firejox
firejox / midpoint.m
Last active October 25, 2017 03:50
midpoint method
function y = my_midpoint_method(f, y0, a, b, n)
h = (b - a) / n
y = 0:n
y(0) = y0
for i = 1:n
y(i) = y(i - 1) + h * f(a + h*(i - 1) + h*0.5, y(i - 1) + 0.5*h*f(a + h*(i - 1), y(i - 1)))
end
end
@firejox
firejox / result
Last active January 18, 2017 20:46
threadring benchmark
# AMD Athlon(tm) II X2 270 Processor
# Arch Linux x86_64
# gcc (GCC) 6.2.1 20160830
# Crystal 0.19.4 (2016-10-07)
Crystal
181
== 1.22s, 4.4Mb ==
Crystal with new channel
181
== 2.39s, 16.7Mb ==
Bug: called create_llvm_type for T
0x752ed7: *CallStack::unwind:Array(Pointer(Void)) at ??
0x752e6a: *CallStack#initialize:Array(Pointer(Void)) at ??
0x752e3a: *CallStack::new:CallStack at ??
0x73051e: *raise<Exception>:NoReturn at ??
0x73050e: ??? at ??
0x13e02d5: ??? at ??
0x13dc0eb: ??? at ??
0x13dc671: *Crystal::LLVMTyper#llvm_embedded_type<Crystal::Type+, Bool>:LLVM::Type at ??
0x13de76f: *Crystal::LLVMTyper#create_llvm_struct_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type at ??
@firejox
firejox / error
Created December 30, 2016 12:48
error message
Error in line 1: while requiring "./channel_spec.cr"
in channel_spec.cr:122: instantiating 'AsyncAwait::Channel(T):Class#select_with_csp()'
AAChannel.select_with_csp do |x|
^~~~~~~~~~~~~~~
in /home/firejox/develop/async_await/src/async_await/channel.cr:290: instantiating 'AsyncAwait::Channel(T):Class#select()'
self.select do |action|
@firejox
firejox / async_await.cr
Created December 21, 2016 15:01
async await toy
lib Intrinsics
fun frameaddress = "llvm.frameaddress"(level : Int32) : Void*
end
module Async
enum Status
INCOMPLETE
COMPLETE
FAULT
end
macro show(qqq)
puts "#{ {{qqq}} }"
end
macro bla(name)
{% if name.is_a?(Def) %}
def {{name.name}}
{% body = name.body %}
{{ body }}
end