Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 06:07 (UTC +09:00)
  • X @methane
View GitHub Profile
@methane
methane / bench_dict.py
Last active May 16, 2022 11:09
dict benchmark
#!/usr/bin/env python3
import pyperf
def build_dict_str(n):
mydict = {str(k): k for k in range(n)}
return mydict, list(mydict)
def build_dict_int(n):
In [3]: filter?
Type: type
String Form:<class 'filter'>
Namespace: Python builtin
Docstring:
filter(function or None, iterable) --> filter object
Return an iterator yielding those items of iterable for which function(item)
is true. If function is None, return the items that are true.
import gevent.monkey
gevent.monkey.patch_all()
import flask
from flask.ext.sqlalchemy import SQLAlchemy
app = flask.Flask(__name__)
app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root@localhost/test'
db = SQLAlchemy(app)
@methane
methane / siphash.cpp
Created October 8, 2021 05:45
create known hashes for siphash13
// create known hash in test_hash
#include <cstdint>
#include <iostream>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
// copied from initconfig.c
@methane
methane / 0.README.md
Last active September 27, 2020 05:48
http-parser vs picohttpparser

go 1.1 scheduler

where

src/pkg/runtime proc.c asm_*.s

design

@methane
methane / gist:4748822
Created February 10, 2013 07:45
GOMAXPROCSについてのメモ
gogoutineてGOMAXPROCSを設定しない限りはシングルスレッドなんですねえ。
GOMAXPROCSはもうちょっとだけ複雑です。
同時に動けるgoroutineの数の制限なのですが、
read などのブロックするかもしれないシステムコールを発行する場合、発行前に「現在実行中のゴルーチン数」をデクリメントして、
システムコールから返ってきたらそれをインクリメントします。
で、デクリメントした時に、他に動けるスレッドがいなかったらスレッド起動して、他のgoroutineが動けるようにします。
他のスレッドがすでにあって眠っていたら、それを起こしてgoroutineを実行させます。
なので、ブロックする処理としない処理を混ぜてもいい感じに動くのです。
で、その、スレッドを作ったり起動したりするのが実はちょっとだけ重いので、ベンチマーク結果を良くするためにはその処理が走らないように、
#http://googledevjp.blogspot.com/2011/04/google-code-jam-2011.html
def solve(rest, boards, counts):
if boards == []:
return rest == 0
board = boards[-1]
count = rest / board
rest = rest % board
while count >= 0:
if solve(rest, boards[0:-1], counts):
@methane
methane / bind_and_setuser.py
Last active February 25, 2018 18:33
Go で 80 番以下のポートを listen するためのスクリプト
#!/usr/bin/python
from __future__ import print_function
import os
import pwd
import socket
import sys
@methane
methane / mylite.py
Created June 22, 2012 12:27
Copy table from mysql to sqlite
#! /usr/bin/python
# coding: utf-8
"""Copy table from mysql to sqlite.
Require:
* SQLAlchemy
* MySQLdb or PyMySQL
Usage: