Skip to content

Instantly share code, notes, and snippets.

View pfreixes's full-sized avatar

Pau Freixes pfreixes

  • Github
  • Barcelona
View GitHub Profile
import asyncio
import time
import random
async def coro(loop, idx):
# distribute coros homogenity along 10 seconds
# to get a homogeneous traffic.
await asyncio.sleep(idx % 10)
if loop.load() > 0.9:
import asyncio
import time
async def coro():
await asyncio.sleep(0)
async def main(loop, coros):
start = loop.time()
for i in range(coros):
import aioredis
import asyncio
OPS = 100000
async def main(loop):
conn = await aioredis.create_redis(('localhost', 6379))
start = loop.time()
for i in range(OPS):
await conn.ping()
package test;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import java.nio.charset.Charset;
public class NettyTest {
public static void main(String[] args) throws Exception {
import socket
import time
s = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 6379))
# give enought time to get the
# data plus the RST Package
time.sleep(1)
var net = require('net');
var sleep = require('sleep');
var client = new net.Socket();
client.connect(6379, '127.0.0.1', function() {
console.log('Connected');
sleep.sleep(10); // wait for data and RST package
});
client.on('data', function(data) {
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
An example client. Run simpleserv.py first before running this.
"""
from __future__ import print_function
from time import sleep

Parsing many lines (lines 1000) (Repeated 10 times)

Time took Python json (Python version): 0.501879239018308

Time took cythonized Python json: 0.08349561202339828

Time took Python json (C version) : 0.05558486797963269

Time took ujson: 0.029640772991115227

@pfreixes
pfreixes / Gevent vs asyncio with libuv.md
Last active May 16, 2021 08:17
Gevent vs asyncio with libuv

The numbers claimed by this benchamark about Gevent [1] comparaed with the numbers got by Asyncio with the uvloop and even with the default loop has left me a bit frozen. Ive repeated a few of them : gevent, asyncio, asyncio-uvloop and go for the echo server and these are the numbers roughly:

For gevent

$ ./echo_client
685393 0.98KiB messages in 30 seconds
Latency: min 0.04ms; max 4.48ms; mean 0.126ms; std: 0.048ms (37.68%)
Latency distribution: 25% under 0.088ms; 50% under 0.122ms; 75% under 0.158ms; 90% under 0.182ms; 99% under 0.242ms; 99.99% under 0.91ms
@pfreixes
pfreixes / immutable.py
Created March 30, 2016 08:35
Immutable made easy with Python
class ImmutableRecord(object):
def __init__(self, name):
self.__name = name
@property
def name(self):
return self.__name
def __hash__(self):