Skip to content

Instantly share code, notes, and snippets.

@firejox
Last active September 25, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firejox/104ef75e2f8a0d4c5717b3c22182ba09 to your computer and use it in GitHub Desktop.
Save firejox/104ef75e2f8a0d4c5717b3c22182ba09 to your computer and use it in GitHub Desktop.
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
Vendor ID: AuthenticAMD
CPU family: 16
Model: 6
Model name: AMD Athlon(tm) II X2 270 Processor
Stepping: 3
CPU MHz: 800.000
CPU max MHz: 3400.0000
CPU min MHz: 800.0000
BogoMIPS: 6833.52
Virtualization: AMD-V
L1d cache: 64K
L1i cache: 64K
L2 cache: 1024K
NUMA node0 CPU(s): 0,1
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
Crystal old [firejox/crystal branch:master]
181
Command being timed: "./fiber-cr-old 5000000"
User time (seconds): 2.08
System time (seconds): 0.01
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.12
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 5664
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 810
Voluntary context switches: 9
Involuntary context switches: 170
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Crystal new [firejox/crystal branch:fiber-context-benchmark]
181
Command being timed: "./fiber-cr-new 5000000"
User time (seconds): 2.00
System time (seconds): 0.01
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.04
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 5596
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 806
Voluntary context switches: 11
Involuntary context switches: 160
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
# https://github.com/kostya/crystal-benchmarks-game/blob/master/threadring/threadring.cr
THREAD_COUNT = 503
class Receiver
def initialize(@name : Int32)
@mailbox = Channel(Int32).new
end
def next=(n : Receiver)
@next = n
end
def put(msg)
@mailbox.send(msg)
end
def messageloop
while true
msg = @mailbox.receive
if msg == 0
RES.send(@name)
elsif nxt = @next
nxt.put(msg - 1)
end
end
end
end
RES = Channel(Int32).new
receivers = Array.new(THREAD_COUNT) { |i| Receiver.new(i + 1) }
(0...THREAD_COUNT - 1).each { |i| receivers[i].next = receivers[i + 1] }
receivers[THREAD_COUNT - 1].next = receivers[0]
THREAD_COUNT.times do |i|
spawn { receivers[i].messageloop }
end
receivers[0].put((ARGV[0]? || 1000).to_i)
puts RES.receive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment