環境は https://gist.github.com/methane/02da76bd619fad8026b5 と同じ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create known hash in test_hash | |
#include <cstdint> | |
#include <iostream> | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <string.h> | |
// copied from initconfig.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gogoutineてGOMAXPROCSを設定しない限りはシングルスレッドなんですねえ。 | |
GOMAXPROCSはもうちょっとだけ複雑です。 | |
同時に動けるgoroutineの数の制限なのですが、 | |
read などのブロックするかもしれないシステムコールを発行する場合、発行前に「現在実行中のゴルーチン数」をデクリメントして、 | |
システムコールから返ってきたらそれをインクリメントします。 | |
で、デクリメントした時に、他に動けるスレッドがいなかったらスレッド起動して、他のgoroutineが動けるようにします。 | |
他のスレッドがすでにあって眠っていたら、それを起こしてgoroutineを実行させます。 | |
なので、ブロックする処理としない処理を混ぜてもいい感じに動くのです。 | |
で、その、スレッドを作ったり起動したりするのが実はちょっとだけ重いので、ベンチマーク結果を良くするためにはその処理が走らないように、 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from __future__ import print_function | |
import os | |
import pwd | |
import socket | |
import sys | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# coding: utf-8 | |
"""Copy table from mysql to sqlite. | |
Require: | |
* SQLAlchemy | |
* MySQLdb or PyMySQL | |
Usage: |