Linuxコマンド集 – 【 time 】 指定したコマンドの実行時間を表示する:ITpro
なんだよ、こんな便利なコマンドがあったのかい!
これで Python と Gjs の速度比較が簡単になる。
function printDateFormat(ms) {
let date = new Date(ms);
let s = date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds();
print(s);
}
ってのを Gjs 用に考えたけどいらなかった。
てなわけで、早速 Gio.Subprocess で差が出るか確認してみよう。
前回のコードから不要な部分をバッサリ省いて。
#!/usr/bin/env python3
import gi
gi.require_version('GdkPixbuf', '2.0')
from gi.repository import Gio, GLib, GdkPixbuf
namelist = []
unzip_list = []
sp = Gio.Subprocess.new(["unzip", "-Z", "test.cbz"], Gio.SubprocessFlags.STDOUT_PIPE);
istream = sp.get_stdout_pipe()
dstream = Gio.DataInputStream(base_stream=istream)
while True:
line, l = dstream.read_line_utf8()
if line == None: break
if line.startswith('-'):
name = line[53:]
if GLib.Regex.match_simple("\.(jpe?g|png|gif)$", name, GLib.RegexCompileFlags.CASELESS, 0):
namelist.append(name)
for name in namelist:
sp = Gio.Subprocess.new(["unzip", "-p", "test.cbz", name], Gio.SubprocessFlags.STDOUT_PIPE)
stream = sp.get_stdout_pipe()
p = GdkPixbuf.Pixbuf.new_from_stream(stream, None);
unzip_list.append(p)
stream.close()
Gjs で書き換えて。
#!/usr/bin/gjs
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const GdkPixbuf = imports.gi.GdkPixbuf;
let namelist = [];
let unzip_list = [];
let sp = Gio.Subprocess.new(["unzip", "-Z", "test.cbz"], Gio.SubprocessFlags.STDOUT_PIPE);
let istream = sp.get_stdout_pipe();
let dstream = new Gio.DataInputStream({base_stream:istream});
for (;;) {
let [line, l] = dstream.read_line_utf8(null);
if (line == null) break;
if (line.startsWith('-')) {
let name = line.slice(53);
if (GLib.Regex.match_simple("\.(jpe?g|png|gif)$", name, GLib.RegexCompileFlags.CASELESS, 0))
namelist.push(name);
}
}
for (let i=0; i<namelist.length; i++) {
let sp = Gio.Subprocess.new(["unzip", "-p", "test.cbz", namelist[i]], Gio.SubprocessFlags.STDOUT_PIPE);
let stream = sp.get_stdout_pipe();
let p = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
unzip_list.push(p);
stream.close(null);
}
コレを time コマンドで比較。

って一秒すらも差が出ない誤差の範囲ジャン!
Gjs 版 Comipoli が異様に遅い原因は言語のせいでは無いことは判明した。