DEV Community

Atsumi
Atsumi

Posted on

 

GNU timeを知った

High Performance Python 2nd Editionを読む中で、
timeはGNU版と簡易版の二つがあることを知った。

time(シェル組み込み)

bashやzshのプロンプトでパスが通っている timeはシェル組み込みのtimeで、簡易版らしい。

# zsh
$ time sleep 1
sleep 1  0.00s user 0.00s system 0% cpu 1.004 total

GNU time

/usr/bin/timeにインストールされたコマンドはGNU版で、上記よりもリッチな情報を出すことができる。

macの場合はbrew install gnu-timegtimeとしてインストール可能。

$ gtime --verbose sleep 1
        Command being timed: "sleep 1"
        User time (seconds): 0.00
        System time (seconds): 0.00
        Percent of CPU this job got: 0%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.00
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 612
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 297
        Voluntary context switches: 0
        Involuntary context switches: 17
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Major (requiring I/O) page faultsは、スワップの発生を意味しており注意すべきメトリクスである。

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.