Skip to content

Instantly share code, notes, and snippets.

View methane's full-sized avatar

Inada Naoki methane

  • KLab Inc,
  • Japan
  • 22:39 (UTC +09:00)
  • X @methane
View GitHub Profile
=== time ===
iostream.py:708 write_to_fd 49.797434
iostream.py:773 set_nodelay 31.600270
iostream.py:696 read_from_fd 15.023633
kqueue.py:67 poll 2.160702
<frozen importlib._bootstrap>:1879 _path_importer_cache 0.101283
<frozen importlib._bootstrap>:656 _compile_bytecode 0.101283
web.py:1379 <listcomp> 0.067522
web.py:1378 _generate_headers 0.067522
<frozen importlib._bootstrap>:321 _call_with_frames_removed 0.033761
474286 function calls (468756 primitive calls) in 38.130 seconds
Ordered by: call count
ncalls tottime percall cumtime percall filename:lineno(function)
38848 0.016 0.000 0.023 0.000 {built-in method isinstance}
24354/24259 0.004 0.000 0.004 0.000 {built-in method len}
13000 0.012 0.000 0.023 0.000 escape.py:193(utf8)
12012/12011 0.004 0.000 0.007 0.000 {method 'encode' of 'str' objects}
11202 0.013 0.000 0.013 0.000 {built-in method hasattr}
@methane
methane / u8bench.py
Created August 27, 2014 17:24
Benchmark of tornado.speedup.utf8
#micro benchmark
#CPython 3.4.1
import timeit
print(timeit.timeit("utf8('xyzzy')", "from tornado.escape import utf8"))
# $ TORNADO_EXTENSION=1 python u8bench.py
# 0.0813535709748976
# $ TORNADO_NO_EXTENSION=1 python u8bench.py
# 0.8695125280064531
@methane
methane / chat.go
Last active August 29, 2015 14:05
シンプルなチャット https://github.com/methane/go-chat-sample に移動
package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"log"
"net"
"os"
package main
import (
"io"
"log"
"net"
"sync"
"time"
)
methane@raring:~$ uname -a
Linux raring 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
methane@raring:~$ gcc -O2 -o gt gt.c
methane@raring:~$ time ./gt
called 1000000 times, last value is 1412062858.602343
real 0m2.219s
user 0m2.215s
sys 0m0.005s
YYY YYY
RRR RRR
BBB BBB
GGG GGG
@methane
methane / hello.go
Created October 30, 2014 14:37
Go 1.3.3 vs Go 1.4b1 : HTTP Hello Server
package main
import (
"log"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/plain")
w.Write([]byte("Hello, World."))
ROUTINE ====================== net/http.ReadRequest
11 403 samples (flat, cumulative) 27.2% of total
-------------------- /home/ec2-user/local/go/src/net/http/request.go
2 2 591: func ReadRequest(b *bufio.Reader) (req *Request, err error) {
. . 447b70: FS MOVQ FS:0xfffffff0, CX
2 2 447b79: LEAQ 0xffffff30(SP), AX
. . 447b81: CMPQ 0x10(CX), AX
. . 447b85: JA 0x447b8e
. . 447b87: CALL runtime.morestack_noctxt(SB)
. . 447b8c: JMP net/http.ReadRequest(SB)
$ python -c "import sys; print(sys.stdout.encoding)"
UTF-8
$ python -c "import sys; print(sys.stdout.encoding)" | cat
None
$ PYTHONIOENCODING=utf-8 python -c "import sys; print(sys.stdout.encoding)" | cat
utf-8
$ python3 -c "import sys; print(sys.stdout.encoding)"
UTF-8
$ python3 -c "import sys; print(sys.stdout.encoding)" | cat
UTF-8