Skip to content

Instantly share code, notes, and snippets.

Avatar

Pau Freixes pfreixes

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

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 Mar 16, 2020
Inferncia del numero de infectats
View script.py
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)
View sync_on_top_of_aio.py
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 Dec 12, 2019
Compare performance conditionals between if None and if []
View test.py
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
Test experimental gRPC using Native Asyncio
View test_client.py
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
View gist:65db5634a5723d0ffd6d3af18eaf0f5a
$ 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 Jul 18, 2018
Comparing Proto vs JSON with Python
View address_book.proto
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 Jun 8, 2018
JSON fallback for protobuf is so slow!
View json_fallback.py
>>> 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 Jun 1, 2018
UVloop tracing test dns tracing
View test_dns_tracing.py
import asyncio
import contextvars
import uvloop
from types import SimpleNamespace
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
trace_context = contextvars.ContextVar('trace_context')