Skip to content

Instantly share code, notes, and snippets.

View hansonkd's full-sized avatar

Kyle Hanson hansonkd

  • Statetrace
View GitHub Profile
@hansonkd
hansonkd / readme.md
Last active August 17, 2022 14:14
Redis vs HTTP benchmark

Redis vs HTTP Benchmarks

See the original blog post

Results:

Name                           ips        average  deviation         median         99th %
redix_pool                   70.44       14.20 ms    ±36.07%       13.30 ms       50.60 ms
run_redix_pipeline 30.56 32.73 ms ±65.74% 47.26 ms 91.99 ms
@hansonkd
hansonkd / FizzBuzzElixir.ex
Created November 8, 2021 16:40
FizzBuzz Benchmarks in elixir
defmodule Mix.Tasks.Statetrace.RunBench do
use Mix.Task
alias Statetrace.Meta
@impl Mix.Task
# credo:disable-for-next-line
def run(_) do
list = Enum.to_list(1..10_000)
map_fun = fn i -> [i, i * i] end
Model
.objects
.filter(...)
.order_by(...)
.reverse()
with open('file_output.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=['Label', 'Issue Date'])
for security in flat_securities:
writer.write_row({'Label': security.label, 'Issue Date': security.issue_date})
all_securities = Security.objects.filter(company=company).for_report().iterator()
def flatten(*args):
def transform_pipeline(mdl):
data = FlatData()
for fn in args:
fn(data, mdl)
return data
return transform_pipeline
all_securities = Security.objects.filter(company=company).for_report().iterator()
class FlatData(object):
pass
def add_issue_date((flat, mdl)):
flat.issue_date = mdl.get_issue_date()
return (flat, mdl)
def add_label((flat, mdl)):
def func1(obj):
return do_stuff(obj)
def func2(self):
return do_other_stuff(obj)
def func3(self):
return do_more_stuff(obj)
composed = compose(
class Obj(object):
def method1(self):
return do_stuff(self)
def method2(self):
return do_other_stuff(self)
def method3(self):
return do_more_stuff(self)
books = get_book_row_generator_from_csv('mybooks.csv')
formatted_books = (
conduit(books)
.map(Book.from_row)
.filter(lambda book: book.year >= 1950)
.sort(lambda book: (book.year, book.author_name.lower()))
.map('{0.title} | {0.author} ({0.year})'.format)
.to_list()
)
books = get_book_row_generator_from_csv('mybooks.csv')
formatted_books = list(
map(
sorted(
filter(
map(
books,
Book.from_row
),
lambda: book.year >= 1950