Skip to content

Instantly share code, notes, and snippets.

View pfreixes's full-sized avatar

Pau Freixes pfreixes

  • Github
  • Barcelona
View GitHub Profile
@pfreixes
pfreixes / read.go
Last active August 12, 2021 15:56
Test for checking maximum throughput of random reads over a 40GB file stored in a SSD disk
package main
import (
"fmt"
"math/rand"
"os"
"sync"
"time"
)
@pfreixes
pfreixes / README.md
Created January 7, 2021 22:24
Emcache vs Go for checking ops/sec and latencies of GETs and SETs for a Memcache server

Go using 1 CPU

$ GOMAXPROCS=1 ./stress 
GET Test results
Ops/sec:  100015
P50: 0.000304 seconds
P99: 0.000825 seconds

SET Test results
@pfreixes
pfreixes / script.py
Created March 16, 2020 21:23
Inferncia del numero de infectats
TAXA_DE_MULTIPLICACIO = 3
PERCENTATGE_DE_HOSPITALITZATS = 20
casos_reportats = [18, 28, 32, 45, 48, 77, 100, 124, 181, 319, 509, 715, 903, 1394]
casos_reals = casos_reportats[0]
for i in range(1, len(casos_reportats)):
casos_reals += ((casos_reportats[i] - casos_reportats[i-1]) * 100 / PERCENTATGE_DE_HOSPITALITZATS) * TAXA_DE_MULTIPLICACIO
print(casos_reals)
import asyncio
import grpc
from grpc.experimental import aio
from proto import echo_pb2
from proto import echo_pb2_grpc
async def run_sync_request(loop):
@pfreixes
pfreixes / test.py
Created December 12, 2019 12:01
Compare performance conditionals between if None and if []
import time
N = 1000000
def benchmark():
l = None
start = time.time()
for i in range(N):
if l:
pass
@pfreixes
pfreixes / test_client.py
Last active May 3, 2019 15:26
Test experimental gRPC using Native Asyncio
import asyncio
import pytest
import subprocess
import time
from grpc_asyncio import grpc_init_asyncio
from grpc_asyncio import create_channel
from tests.acceptance.fixtures import echo_pb2
$ python
Python 3.7.2 (default, Jan 13 2019, 12:51:54)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> f = [1, 2, 3]
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'f']
>>> for x in f:
@pfreixes
pfreixes / address_book.proto
Last active July 18, 2018 21:00
Comparing Proto vs JSON with Python
syntax = "proto2";
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
@pfreixes
pfreixes / json_fallback.py
Created June 8, 2018 14:54
JSON fallback for protobuf is so slow!
>>> timeit.timeit("""json.dumps({"name": "foo", "id":1})""", setup="from __main__ import json", number=10000)
0.04011281501152553
>>> timeit.timeit("json_format.MessageToJson(person)", setup="from __main__ import json_format, person", number=10000)
0.2599130409944337
>>> person
name: "foo"
id: 1
@pfreixes
pfreixes / test_dns_tracing.py
Created June 1, 2018 07:21
UVloop tracing test dns tracing
import asyncio
import contextvars
import uvloop
from types import SimpleNamespace
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
trace_context = contextvars.ContextVar('trace_context')