Skip to content

Instantly share code, notes, and snippets.

View xjdrew's full-sized avatar
:octocat:

xjdrew xjdrew

:octocat:
View GitHub Profile
@xjdrew
xjdrew / lua-utf8.c
Created January 15, 2014 16:05
lualib, 把字符串从utf8解成utf-16;并返回长度,解码失败,返回nil;
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include "lua.h"
#include "lauxlib.h"
inline int
_bytes(uint8_t c) {
if(c < 0x80) return 1;
@xjdrew
xjdrew / async_call.py
Last active December 21, 2015 22:29
用gevent变异步调用为同步
import gevent
from gevent.queue import Queue
q = Queue()
session = {}
def producer():
i = 1
while True:
q.put(i)
@xjdrew
xjdrew / co1.lua
Last active December 21, 2015 15:29
coroutine比较,lua的实现更科学一点。
function test1(co2)
print(12)
coroutine.resume(co2)
print(34)
coroutine.resume(co2)
end
function test2()
print(56)
@xjdrew
xjdrew / ping_client.py
Last active December 21, 2015 13:49
ping -> pong server 效率: 单连接: python 2.1W每秒 erlang 4.6W每秒 redis 2.7W每秒 多连接(100)个: python 3W每秒 erlang 11W 每秒 redis 13W每秒 CPU: Intel i5-2400 [email protected]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gevent
from gevent import monkey;monkey.patch_all()
import sys, argparse, socket, time
def ping(sock, requests):
fileobj = sock.makefile()
for i in xrange(requests):
sock.sendall("PING\r\n")