<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; grep sed perl awk - что быстрее для простых выборок]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=26969</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=26969&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «grep sed perl awk - что быстрее для простых выборок».]]></description>
		<lastBuildDate>Sat, 02 Mar 2013 06:27:37 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330859#p330859</link>
			<description><![CDATA[<div class="quotebox"><cite>Civil пишет:</cite><blockquote><p>Для некоторых версий awk&#039;а сильно помогает сказать LC_ALL=&quot;C&quot;, например.</p></blockquote></div><p> зачем искать костыли, если и так четко видно что для данной задачи этот инструмент не подходит, так как выполняет ее в разы медленнее.</p>]]></description>
			<author><![CDATA[null@example.com (valet)]]></author>
			<pubDate>Sat, 02 Mar 2013 06:27:37 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330859#p330859</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330801#p330801</link>
			<description><![CDATA[<p>Это тоже бывает. Для некоторых версий awk&#039;а сильно помогает сказать LC_ALL=&quot;C&quot;, например.</p>]]></description>
			<author><![CDATA[null@example.com (Civil)]]></author>
			<pubDate>Fri, 01 Mar 2013 18:35:11 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330801#p330801</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330742#p330742</link>
			<description><![CDATA[<div class="quotebox"><cite>Civil пишет:</cite><blockquote><p>Есть несколько реализаций awk, которые принципиально отличаются по скорости.<br />Например на чтении 300МБ файла (1.5млн строк, источник) разница примерно следующая:</p></blockquote></div><p>это то понятно... меня удивило, что между гнутыми 3-м и 4-м разница в 4 раза получается...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Fri, 01 Mar 2013 13:46:24 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330742#p330742</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330613#p330613</link>
			<description><![CDATA[<p>Про awk&#039;и:<br />Есть несколько реализаций awk, которые принципиально отличаются по скорости.<br />Например на чтении 300МБ файла (1.5млн строк, источник) разница примерно следующая:<br />gawk - 0m1.871s<br />mawk - 0m0.469s</p>]]></description>
			<author><![CDATA[null@example.com (Civil)]]></author>
			<pubDate>Fri, 01 Mar 2013 07:12:49 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330613#p330613</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330585#p330585</link>
			<description><![CDATA[<div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>ИРЛ это даёт профит только если чтение с диска не требуется...</p></blockquote></div><p>Просто для эксперимента оставил в варианте на Python и GO только построчное чтение файла, дык GO оказался в несколько раз медленнее...<br /></p><div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>так что отдельного потока чтения будет даже лучше в большинстве задач...</p></blockquote></div><p>&quot;Одного&quot; ты хотел сказать?<br />Погуглив, выяснил, что GO быстрее работает со срезами байтов, чем со строками. <br /></p><div class="codebox"><pre><code>package main

import (
    &quot;bufio&quot;
    &quot;fmt&quot;
    &quot;os&quot;
    &quot;regexp&quot;
)

func main() {

    if len(os.Args) != 3 {
        fmt.Printf(&quot;Usage: %s &lt;substring&gt; &lt;filename&gt;\n&quot;, os.Args[0])
        return
    }
    substr := os.Args[1]
    fname := os.Args[2]

    f, err := os.Open(fname)
    if err != nil {
        return
    }
    defer f.Close()

    r := bufio.NewReader(f)
    patt, _ := regexp.Compile(substr)

    for {

        s, ok := r.ReadSlice(&#039;\n&#039;)
        if ok != nil {
            break
        }
        matches := patt.Match(s)
        if matches {
            fmt.Print(string(s))
        }

    }

}</code></pre></div><p>Этот вариант в полтора раза быстрее... По скорости чтения слегка обошёл Python. Теперь затык в регулярке.</p>]]></description>
			<author><![CDATA[null@example.com (-=Serj=-)]]></author>
			<pubDate>Fri, 01 Mar 2013 05:34:08 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330585#p330585</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330495#p330495</link>
			<description><![CDATA[<div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>awk за три года всё же улучшили, видимо...</p></blockquote></div><p> может, у меня искаропки, не менял. Но у тебя же тоже он скоростью не выделяется.</p><div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>за остальным - надо исходники курить... мне лень...</p></blockquote></div><p> Это понятно. Не знаю как кто, но я почему-то думал, что из всех этих grep самый медленный, просто его все юзают потому что он самый удобный, ошибался....</p>]]></description>
			<author><![CDATA[null@example.com (valet)]]></author>
			<pubDate>Thu, 28 Feb 2013 18:46:19 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330495#p330495</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330492#p330492</link>
			<description><![CDATA[<div class="quotebox"><cite>valet пишет:</cite><blockquote><p>По поводу версий:</p></blockquote></div><p>awk за три года всё же улучшили, видимо...<br /></p><div class="quotebox"><cite>valet пишет:</cite><blockquote><p>И все таки - почему же grep явный лидер, что там код настолько кардинально лучше написан, что оно выигрывает. В чем секрет?</p></blockquote></div><p>просто он только и умеет, что искать строчки....</p><p>из явных отличий:<br />grep читает из файла по 32к блоками, а остальные(кроме питона) 4к-страницами.... <br />скорей всего это из-за того, что sedperlawk читает через stdio&#039;шные средства, а не системные... соответственно отсюда не меньше, чем 2-й оверхед при чтении..</p><p>за остальным - надо исходники курить... мне лень...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Thu, 28 Feb 2013 18:40:16 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330492#p330492</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330481#p330481</link>
			<description><![CDATA[<div class="quotebox"><cite>-=Serj=- пишет:</cite><blockquote><p>Кстати, возник такой вопрос. Как организовать многопоточное построчное чтение текстового файла?</p></blockquote></div><p> xargs, не?</p>]]></description>
			<author><![CDATA[null@example.com (valet)]]></author>
			<pubDate>Thu, 28 Feb 2013 18:11:49 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330481#p330481</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330480#p330480</link>
			<description><![CDATA[<div class="codebox"><pre><code>valet@valet-comp:~/Documents/all$ time ./go-grep foo all &gt; /dev/null 

real    0m10.354s
user    0m10.221s
sys    0m0.124s
valet@valet-comp:~/Documents/all$ time ./go-grep2 foo all &gt; /dev/null 

real    0m6.957s
user    0m6.852s
sys    0m0.100s</code></pre></div><p>Совсем как-то медленно, че-то этот GO не очень...</p><p><strong>Fat-Zer</strong>, спасибо за результаты - интересно.</p><p>По поводу версий:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>valet@valet-comp:~/Documents/all$ grep --version
GNU grep 2.6.3

Copyright (C) 2009 Free Software Foundation, Inc.
Лицензия GPLv3+: GNU GPL версии 3 или новее &lt;http://gnu.org/licenses/gpl.html&gt;
Это свободное ПО: вы можете продавать и распространять его.
Нет НИКАКИХ ГАРАНТИЙ до степени, разрешённой законом.

valet@valet-comp:~/Documents/all$ perl --version

This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
(with 59 registered patches, see perl -V for more detail)

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using &quot;man perl&quot; or &quot;perldoc perl&quot;.  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

valet@valet-comp:~/Documents/all$ awk --version
GNU Awk 3.1.7
Copyright (C) 1989, 1991-2009 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
valet@valet-comp:~/Documents/all$ sed --version
GNU sed версия 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

GNU sed home page: &lt;http://www.gnu.org/software/sed/&gt;.
General help using GNU software: &lt;http://www.gnu.org/gethelp/&gt;.
E-mail bug reports to: &lt;bug-gnu-utils@gnu.org&gt;.
Be sure to include the word ``sed&#039;&#039; somewhere in the ``Subject:&#039;&#039; field.
valet@valet-comp:~/Documents/all$ python --version
Python 2.6.6
valet@valet-comp:~/Documents/all$ </code></pre></div></div></div><p>И все таки - почему же grep явный лидер, что там код настолько кардинально лучше написан, что оно выигрывает. В чем секрет?</p>]]></description>
			<author><![CDATA[null@example.com (valet)]]></author>
			<pubDate>Thu, 28 Feb 2013 18:08:34 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330480#p330480</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330471#p330471</link>
			<description><![CDATA[<div class="quotebox"><cite>-=Serj=- пишет:</cite><blockquote><p>Кстати, возник такой вопрос. Как организовать многопоточное построчное чтение текстового файла?</p></blockquote></div><p>самое простое, что приходит на ум: mmap&#039;ишь, первый поток читает с начала, второй — тычется в середину, находит конец строки и читает оттуда...</p><p>ИРЛ это даёт профит только если чтение с диска не требуется... так что отдельного потока чтения будет даже лучше в большинстве задач...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Thu, 28 Feb 2013 17:11:01 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330471#p330471</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330460#p330460</link>
			<description><![CDATA[<p>Кстати, возник такой вопрос. Как организовать многопоточное построчное чтение текстового файла?</p>]]></description>
			<author><![CDATA[null@example.com (-=Serj=-)]]></author>
			<pubDate>Thu, 28 Feb 2013 16:34:39 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330460#p330460</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330425#p330425</link>
			<description><![CDATA[<p><strong>Fat-Zer</strong>, какая версия Python у тебя? И какая у <strong>valet</strong>?<br />3.2 медленнее 2.7, 3.3 чуть медленнее 2.7.</p><p>UPD. Ага, уже указал...</p><p>ЗЗЫ. Хм, у меня Python отрабатывает быстрее Go.</p>]]></description>
			<author><![CDATA[null@example.com (-=Serj=-)]]></author>
			<pubDate>Thu, 28 Feb 2013 13:38:03 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330425#p330425</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330424#p330424</link>
			<description><![CDATA[<p>отсюда вопрос: <strong>valet</strong>, что у тебя за кривой awk такой? </p><p>[копирайты отрезаны]<br /></p><div class="codebox"><pre><code>alexander@goblin /tmp $ grep --version
grep (GNU grep) 2.14
alexander@goblin /tmp $ perl --version
This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux
(with 12 registered patches, see perl -V for more detail)
alexander@goblin /tmp $ awk --version
GNU Awk 4.0.1
alexander@goblin /tmp $ sed --version
GNU sed версия 4.2.1
alexander@goblin /tmp $ python --version
Python 2.7.3</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Thu, 28 Feb 2013 13:37:24 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330424#p330424</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330387#p330387</link>
			<description><![CDATA[<p>набросал тут тестовый скриптик и прогнал его на сложном выражение... <br />места сильно отличаются:<br /><strong>grep</strong> - бесспорный лидер,<br /><strong>perl</strong> - второе место с многократным отставанием<br /><strong>awk</strong> - немного недотянул до перловки<br /><strong>sed</strong> - на порядок отстаёт от остальных<br /><strong>python</strong> - плетётся в самом конце</p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;результаты</div><div class="fancy_spoiler"><p><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh"><span style="color: cyan"># тестировать будем на исходниках ядра</span><br />alexander@goblin /tmp $ find linux-3.0/ -type f -exec cat {} + | tee megafile |wc -l<br />14647033<br /><span style="color: cyan"># <strong>сложное выражение</strong></span><br />alexander@goblin /tmp $ ./grep-test.sh &#039;\s*return.*;&#039;<br />wc -l for&nbsp; &nbsp;grep: 411133<br />wc -l for&nbsp; &nbsp;perl: 411133<br />wc -l for&nbsp; &nbsp; awk: 411133<br />wc -l for&nbsp; &nbsp; sed: 411133<br />wc -l for python: 411133<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; &nbsp;4.04 (avg&nbsp; 0.40)<br />time for&nbsp; &nbsp;perl:&nbsp; 27.28 (avg&nbsp; 2.73)<br />time for&nbsp; &nbsp; awk:&nbsp; 28.76 (avg&nbsp; 2.88)<br />time for&nbsp; &nbsp; sed: 174.89 (avg 17.49)<br />time for python: 182.10 (avg 18.21)<br /><span style="color: cyan"># <strong>простое выражение</strong><br /># все улучшили результаты, отставание аутсайдеров сократилось </span><br />wc -l for&nbsp; &nbsp;grep: 453902<br />wc -l for&nbsp; &nbsp;perl: 453902<br />wc -l for&nbsp; &nbsp; awk: 453902<br />wc -l for&nbsp; &nbsp; sed: 453902<br />wc -l for python: 453902<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; &nbsp;4.23 (avg&nbsp; 0.42)<br />time for&nbsp; &nbsp;perl:&nbsp; 25.33 (avg&nbsp; 2.53)<br />time for&nbsp; &nbsp; awk:&nbsp; 28.56 (avg&nbsp; 2.86)<br />time for&nbsp; &nbsp; sed:&nbsp; 36.24 (avg&nbsp; 3.62)<br />time for python:&nbsp; 69.19 (avg&nbsp; 6.92)<br /><span style="color: cyan"># <strong>не встречающееся простое выражение</strong><br /># ещё немного лучше, примечательно трёхкратное, улучшение <strong>grep</strong>&#039;а, sed наоборот немного скатился</span><br />./grep_test.sh &#039;this_statment_is_false&#039;<br />wc -l for&nbsp; &nbsp;grep:0<br />wc -l for&nbsp; &nbsp;perl:0<br />wc -l for&nbsp; &nbsp; awk:0<br />wc -l for&nbsp; &nbsp; sed:0<br />wc -l for python:0<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; &nbsp;1.60 (avg&nbsp; 0.16)<br />time for&nbsp; &nbsp;perl:&nbsp; 21.87 (avg&nbsp; 2.19)<br />time for&nbsp; &nbsp; awk:&nbsp; 28.30 (avg&nbsp; 2.83)<br />time for&nbsp; &nbsp; sed:&nbsp; 37.31 (avg&nbsp; 3.73)<br />time for python:&nbsp; 68.18 (avg&nbsp; 6.82)<br /><span style="color: cyan"># <strong>не встречающееся сложное выражение</strong><br /># без особых изменений</span><br />alexander@goblin /tmp $ ./grep_test.sh &#039;this.*statment.*is.*false[!?]&#039;<br />wc -l for&nbsp; &nbsp;grep:0<br />wc -l for&nbsp; &nbsp;perl:0<br />wc -l for&nbsp; &nbsp; awk:0<br />wc -l for&nbsp; &nbsp; sed:0<br />wc -l for python:0<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; &nbsp;2.80 (avg&nbsp; 0.28)<br />time for&nbsp; &nbsp;perl:&nbsp; 22.88 (avg&nbsp; 2.29)<br />time for&nbsp; &nbsp; awk:&nbsp; 28.24 (avg&nbsp; 2.82)<br />time for&nbsp; &nbsp; sed:&nbsp; 45.55 (avg&nbsp; 4.55)<br />time for python:&nbsp; 68.14 (avg&nbsp; 6.81)<br /><span style="color: cyan"># <strong>короткое часто встречающееся и простое выражение</strong><br /># а вот и вариант, где <strong>perl</strong> проигрывает <strong>awk</strong></span><br />alexander@goblin /tmp $ ./grep_test.sh &#039; &#039;<br />wc -l for&nbsp; &nbsp;grep:9869702<br />wc -l for&nbsp; &nbsp;perl:9869702<br />wc -l for&nbsp; &nbsp; awk:9869702<br />wc -l for&nbsp; &nbsp; sed:9869702<br />wc -l for python:9869702<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; 29.31 (avg&nbsp; 2.93)<br />time for&nbsp; &nbsp;perl:&nbsp; 32.03 (avg&nbsp; 3.20)<br />time for&nbsp; &nbsp; awk:&nbsp; 28.74 (avg&nbsp; 2.87)<br />time for&nbsp; &nbsp; sed:&nbsp; 39.30 (avg&nbsp; 3.93)<br />time for python:&nbsp; 87.30 (avg&nbsp; 8.73)<br /><span style="color: cyan"># <strong>короткое часто встречающееся и сложное выражение</strong><br /># ещё один вариант, где <strong>perl</strong> лажает... примечателен также тем, что sed не нашёл 15 строк</span><br />alexander@goblin /tmp $ ./grep_test.sh &#039;\S&#039;<br />wc -l for&nbsp; &nbsp;grep:12654337<br />wc -l for&nbsp; &nbsp;perl:12654337<br />wc -l for&nbsp; &nbsp; awk:12654337<br />wc -l for&nbsp; &nbsp; sed:12654324<br />wc -l for python:12654337<br />tests number: 10<br />time for&nbsp; &nbsp;grep:&nbsp; 11.70 (avg&nbsp; 1.17)<br />time for&nbsp; &nbsp;perl:&nbsp; 47.23 (avg&nbsp; 4.72)<br />time for&nbsp; &nbsp; awk:&nbsp; 27.82 (avg&nbsp; 2.78)<br />time for&nbsp; &nbsp; sed:&nbsp; 70.22 (avg&nbsp; 7.02)<br />time for python: 112.62 (avg 11.26)</div></p></div></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;grep_test.sh</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#!/bin/bash

REG_EXP=&quot;$1&quot;
FILE=&quot;/tmp/megafile&quot;
TEST_NUM=10

PYTHON_SCRIPT=&quot;/tmp/grep.py&quot;

SED_CMD=(sed -ne &quot;/$REG_EXP/p&quot;)
GREP_CMD=(grep &quot;$REG_EXP&quot;)
PERL_CMD=(perl -ne &quot;print if /$REG_EXP/&quot;)
AWK_CMD=(awk &quot;/$REG_EXP/ { print }&quot;)
PYTHON_CMD=(python ${PYTHON_SCRIPT} &quot;$REG_EXP&quot;)

GNU_TIME=&quot;/usr/bin/time&quot;

LC_ALL=C

wc_l() {
    printf &quot;wc -l for %6s: &quot; &quot;${1}&quot; 
    &quot;$@&quot; $FILE | wc -l
}

rtime() {
    overall=0;
    for((i=0; i&lt;$TEST_NUM; i++)); do
        test_time=&quot;$(${GNU_TIME} -p &quot;$@&quot; $FILE 2&gt;&amp;1 1&gt;/dev/null | sed -n &#039;/real\s\(.*\)/{s//\1/;p}&#039;)&quot;
        overall=&quot;$(python -c &quot;print &#039;%10.5f&#039; % ($overall + $test_time)&quot; )&quot;
    done
    python -c &quot;print &#039;time for %6s: %6.2f (avg %5.2f)&#039; % (&#039;${1}&#039;, $overall, $overall / $TEST_NUM)&quot;
}

wc_l &quot;${GREP_CMD[@]}&quot;
wc_l &quot;${PERL_CMD[@]}&quot; 
wc_l &quot;${AWK_CMD[@]}&quot;
wc_l &quot;${SED_CMD[@]}&quot;
wc_l &quot;${PYTHON_CMD[@]}&quot; 

echo &quot;tests number: $TEST_NUM&quot;

rtime &quot;${GREP_CMD[@]}&quot;
rtime &quot;${PERL_CMD[@]}&quot; 
rtime &quot;${AWK_CMD[@]}&quot;
rtime &quot;${SED_CMD[@]}&quot;
rtime &quot;${PYTHON_CMD[@]}&quot;</code></pre></div></div></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;/tmp/grep.py</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#!/usr/bin/env python
#_*_ coding: utf-8 _*_

import sys, re

patt = re.compile(sys.argv[1])

with open(sys.argv[2], &#039;r&#039;) as f:
    for line in f:
        if patt.search(line):
            print line,</code></pre></div></div></div>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Thu, 28 Feb 2013 12:38:55 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330387#p330387</guid>
		</item>
		<item>
			<title><![CDATA[Re: grep sed perl awk - что быстрее для простых выборок]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=330384#p330384</link>
			<description><![CDATA[<div class="quotebox"><cite>valet пишет:</cite><blockquote><div class="quotebox"><cite>-=Serj=- пишет:</cite><blockquote><p>Могу для экспериментов ещё бинарник на Go попробовать собрать</p></blockquote></div><p> попробуй, интересно <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p></blockquote></div><p>Бинарник на GO:<br /><a href="http://ubuntuone.com/2lSIeO2ssKSgBUcUU2iYmU">http://ubuntuone.com/2lSIeO2ssKSgBUcUU2iYmU</a><br />Запускать так же:<br /></p><div class="codebox"><pre><code>./go-grep foo all</code></pre></div><p><strong>ЗЫ</strong>. Этот вариант должен быть по-шустрее первого: <a href="http://ubuntuone.com/2EpcfsqzWPes75UGpHrjlQ">http://ubuntuone.com/2EpcfsqzWPes75UGpHrjlQ</a><br />Исходник:<br /></p><div class="codebox"><pre><code>package main

import (
    &quot;bufio&quot;
    &quot;fmt&quot;
    &quot;os&quot;
    &quot;regexp&quot;
)

func main() {

    if len(os.Args) != 3 {
        fmt.Printf(&quot;Usage: %s &lt;substring&gt; &lt;filename&gt;\n&quot;, os.Args[0])
        return
    }
    substr := os.Args[1]
    fname := os.Args[2]

    f, err := os.Open(fname)
    if err != nil {
        return
    }
    defer f.Close()

    r := bufio.NewReader(f)
    patt, _ := regexp.Compile(substr)

    for {
        s, ok := r.ReadString(&#039;\n&#039;)
        if ok != nil {
            break
        }
        matches := patt.FindString(s)
        if matches != &quot;&quot; {
            fmt.Print(s)
        }

    }

}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (-=Serj=-)]]></author>
			<pubDate>Thu, 28 Feb 2013 12:31:15 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=330384#p330384</guid>
		</item>
	</channel>
</rss>
