Skip to content

Instantly share code, notes, and snippets.

View KamilLelonek's full-sized avatar
🏋️‍♂️
Do you even lift?

Kamil Lelonek KamilLelonek

🏋️‍♂️
Do you even lift?
View GitHub Profile
func gravatarHash(email string) []byte {
return md5.Sum([]byte(email))[:]
}
func gravatarURL(hash [16]byte, size uint32) string {
return fmt.Sprintf("https://www.gravatar.com/avatar/%x?s=%d", hash, size)
}
func gravatar(email string, size uint32) string {
hash := gravatarHash(email)
+ import (
+ context "golang.org/x/net/context"
+ grpc "google.golang.org/grpc"
+ )
+ // Reference imports to suppress errors if they are not otherwise used.
+ var _ context.Context
+ var _ grpc.ClientConn
+
+ // This is a compile-time assertion to ensure that this generated file
syntax = "proto3";
package gravatar;
service GravatarService {
rpc Generate(GravatarRequest) returns (GravatarResponse)
}
message GravatarRequest {
string email = 1;
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: gravatar.proto
package gravatar
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
alias Benchmarks.Util.Connection
conn = Connection.init!()
# ...
Benchee.run(
inputs: inputs,
before_scenario: fn inputs ->
Connection.reset!(conn)
defmodule Benchmarks.Util.Connection do
alias EventStore.{Config, Storage.Initializer}
def init! do
with {:ok, conn} =
Config.parsed()
|> Config.default_postgrex_opts()
|> Postgrex.start_link() do
conn
end
defmodule Util.Reset do
alias EventStore.{Config, Storage.Initializer}
def conn! do
{:ok, conn} = Config.parsed() |> Config.default_postgrex_opts() |> Postgrex.start_link()
conn
end
def do_reset!(conn) do
fn data ->
import Util.{Reset, Combinators}
# ...
conn = conn!()
Benchee.run(
# ...
time: 40,
warmup: 10,
defmodule Util.Combinators do
def then(a, b) do
fn data -> b.(a.(data)) end
end
def a ~> b, do: a |> then(b)
end
defmodule PostgresPubSub.Account do
use Ecto.Schema
@primary_key {:id, :binary_id, autogenerate: true}
schema "accounts" do
field(:username, :string)
end
end