Skip to content

Instantly share code, notes, and snippets.

def level(exp)
level = 1
return level if exp == 0
while true do
next_level = level + 1
level_exp = (10 *(1.7 **level -1.7)/0.7).to_int
next_level_exp = (10 *(1.7 **next_level -1.7)/0.7).to_int
if level_exp < exp && exp <= next_level_exp then
require 'benchmark'
ary = []
ary2 = []
ary3 = []
Benchmark.bm 10 do |r|
r.report "+" do
10000.times { |n| ary += [n] }
end
r.report "push" do
#!/bin/env ruby
require "google_drive"
require 'date'
require 'dotenv/load'
session = GoogleDrive::Session.from_config("config.json")
# Uploads a local file.
session.upload_from_file(ENV["FILE_PATH"], Date.today.strftime('%Y%m%d'), convert: false)
@hiroyukim
hiroyukim / gist:a3878843e22d4f857d6378652ac21bc8
Created June 10, 2021 04:36
fast main.go:3 slow main.go:10
0x0000 00000 (main.go:3) SUBQ $24, SP 0x0000 00000 (main.go:10) SUBQ $24, SP
0x0004 00004 (main.go:3) MOVQ BP, 16(SP) 0x0004 00004 (main.go:10) MOVQ BP, 16(SP)
0x0009 00009 (main.go:3) LEAQ 16(SP), BP 0x0009 00009 (main.go:10) LEAQ 16(SP), BP
0x000e 00014 (main.go:3) FUNCDATA $0, gclocals·1a65e721a2ccc325b382662e7ffee780(SB) 0x000e 00014 (main.go:10) FUNCDATA $0, gclocals·1a65e721a2ccc325b382662e7ffee780(SB)
0x000e 00014 (main.go:3) FUNCDATA $1, gclocals·69c1753bd5f81501d95132d08af04464(SB) 0x000e 00014 (main.go:10) FUNCDATA $1, gclocals·69c1753bd5f81501d95132d08af04464(SB)
0x000e 00014 (main.go:4) MOVQ "".s+56(SP), CX 0x000e 00014 (main.go:11) MOVQ "".s+56(SP), DX
0x0013 00019 (main.go:4) MOVQ "".a+48(SP), DX 0x0013 00019 (main.go:11) MOVQ "".a+32(SP), BX
0x0018 00024 (main.go:4) CMPQ CX, DX 0x0018 00024 (main.go:11) MOVQ "".a+40(SP), SI
0x001b 00027 (main.go:4) JHI 60 0x001d 00029 (main.go:11) XORL AX, AX
0x001d 00029 (main.go:5) MOVQ "".a+32(SP), AX 0x001f 00031 (main.go:11) NOP