View parser_combinators.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
module Parser(T) | |
def self.char(a : Char) | |
CharParser.new(a) | |
end | |
def self.int | |
IntParser.new | |
end |
View gc_peek.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time = Time.monotonic | |
gcfile = File.new("chry_multiplied.fa") | |
at = 0 | |
gc = 0 | |
while true | |
# Peek the IO's buffer | |
peek = gcfile.peek |
View secret_code.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "colorize" | |
enum Color | |
Red | |
Green | |
Blue | |
Yellow | |
Pink | |
Gray |
View constants_vs_inline.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
RANGE = 3..7 | |
a = 1 | |
v = ARGV[0].to_i | |
Benchmark.ips do |x| | |
x.report("constant") do | |
case v |
View maybe_faster.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Crystal source file is a multiple threaded implementation to perform an | |
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N. | |
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1. | |
# Output is the number of twin primes <= N, or in range N1 to N2; the last | |
# twin prime value for the range; and the total time of execution. | |
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu, | |
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning | |
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc). |
View foo.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Crystal source file is a multiple threaded implementation to perform an | |
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N. | |
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1. | |
# Output is the number of twin primes <= N, or in range N1 to N2; the last | |
# twin prime value for the range; and the total time of execution. | |
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu, | |
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning | |
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc). |
View twinprimes.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Crystal source file is a multiple threaded implementation to perform an | |
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N. | |
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1. | |
# Output is the number of twin primes <= N, or in range N1 to N2; the last | |
# twin prime value for the range; and the total time of execution. | |
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu, | |
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning | |
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc). |
View interfaces.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One can write a class that wraps a Proc and calls it: | |
class Handler | |
def initialize(&@proc : -> String) | |
end | |
def call | |
@proc.call | |
end | |
end |
View steps_no_flaws.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
struct Foo | |
def initialize(@size : Int32, @stride : Int32) | |
end | |
def step_from_class | |
0.step(to: @size, by: @stride) do |i| | |
yield i | |
end |
View steps.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
struct Foo | |
def initialize(@size : Int32, @stride : Int32) | |
end | |
def step_from_class | |
0.step(to: @size, by: @stride) do |i| | |
yield i | |
end |
NewerOlder