Skip to content

Instantly share code, notes, and snippets.

View asterite's full-sized avatar

Ary Borenszweig asterite

  • NoRedInk
  • Buenos Aires, Argentina
View GitHub Profile
require "benchmark"
RANGE = 3..7
a = 1
v = ARGV[0].to_i
Benchmark.ips do |x|
x.report("constant") do
case v
# 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).
# 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).
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
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
def reset
user = current_user
return unless user
user_id = user.id
return unless user_id
server = VirtualMachine.find_by(user_id: user_id, id: params[:server_id])
return unless server
require "spec"
require "json"
require "yaml"
class JSON::Builder
def next_is_object_key?
state = @state.last
state.is_a?(ObjectState) && state.name
end
end
9 - [Bool, Int32, Int64, Slice(UInt8), String, UInt16, UInt32, UInt64, UInt8]
2 - [Crystal::Formatter::HeredocInfo, Crystal::StringInterpolation]
5 - [JSON::Builder::ArrayState, JSON::Builder::DocumentEndState, JSON::Builder::DocumentStartState, JSON::Builder::ObjectState, JSON::Builder::StartState]
3 - [Bool, Crystal::Compiler::Result, Nil]
2 - [Tuple(Int32), Tuple(Int32, Int32)]
2 - [Tuple(Char), Tuple(Char, Char)]
2 - [Pointer(Pointer(Void)), Pointer(Void)]
2 - [Bool, Slice(UInt8)]
3 - [Colorize::Color256, Colorize::ColorANSI, Colorize::ColorRGB]
2 - [HTTP::Headers::Key, String]
+13
+19
+11
+15
+1
+7
+17
+14
-16
+15
diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr
index e108c12f1..59a21ef07 100644
--- a/src/compiler/crystal/semantic/cleanup_transformer.cr
+++ b/src/compiler/crystal/semantic/cleanup_transformer.cr
@@ -23,6 +23,8 @@ module Crystal
initializer.node = initializer.node.transform(transformer)
end
end
+
+ TypesAndMethodsPrinter.new.print_types_and_methods(self)