danforth

danforth
Рейтинг
153
Регистрация
18.12.2015
hakuna matata:
Because it is necessary to take not a single line of 50 characters, and something more;

There's no difference, though large, though small line. And yes, the test is really a synthetic, but it's just an example of what a fast language in some tasks are not always quick in the other.

hakuna matata:
It's not the hundredth, and conditional SO hundredth. Sucked from the finger task and write a new solution, but all have been written for a long time there, and libs.

Liba under a lot of that is, it would be foolish to create a theme, where everyone would be connected libu and made a call to one function. The essence of the theme to pump skill and chat on the topic of code and development (what we do, in principle).

hakuna matata:
не совсем согласен с бенчмарками

Почему не согласны?

hakuna matata:
Ну и зачем вы в сотый раз меряетесь потоковым парсером json, тоже не понимаю.

Тут не в сотый, тема перекочевала из соседней, где задача ну уж совсем легкая была. По мере продвижения, будем поднимать уровень сложности, если конечно это будет кому-то интересно.

hakuna matata:
I do not agree with benchmarks

Why do not you agree?

hakuna matata:
Well, why are you for the hundredth time to measure a streaming parser json, I do not understand.

It's not the hundredth, the theme carried over from the next, where the task well, I was quite easy. As we move, we will raise the level of difficulty, unless of course it will be interesting to someone.

hakuna matata, std библиотека в Go vs std в PHP. Понятное дело, есть та же re2, которая тредится лучше, и на Go она будет быстрее. А если если не скомпилить регулярку в Go, то в цикле можно вообще адово просадить производительность.

В принципе можете сами проверить:

Go без компиляции:


package main

import (
"log"
"regexp"
"time"
)

func main() {
const str = `Если что, я не докапываюсь, но это как? Точнее, какие библиотеки сравнивались? Не верю`
const match = `это (как)\?`

start := time.Now()

for i := 0; i < 1000; i++ {
_, _ = regexp.MatchString(match, str)
}

log.Printf("took: %s", time.Since(start))
}

Go с компиляцией


package main

import (
"log"
"regexp"
"time"
)

func main() {
const str = `Если что, я не докапываюсь, но это как? Точнее, какие библиотеки сравнивались? Не верю`
const match = `это (как)\?`

start := time.Now()

r := regexp.MustCompile(match)

for i := 0; i < 1000; i++ {
_ = r.MatchString(str)
}

log.Printf("took: %v", time.Since(start).Seconds())
}

PHP:


<?php

$str = "Если что, я не докапываюсь, но это как? Точнее, какие библиотеки сравнивались? Не верю";
$pattern = "/это (как)\?/m";

$start = microtime(true);

for ($i = 0; $i < 1000; $i++) {
preg_match($pattern, $str);
}

echo (microtime(true) - $start) . " secs";


Go без компиляции: 0.005807088 секунд
Go с компиляцией: 0.000459663 секунд
PHP: 0.000177860 секунд

hakuna matata, std library in Go vs std in PHP. Of course, it has the same re2 , which trade better, and it will be on the Go faster. And if if not compiled in the regular season Go, then the cycle of hell can generally squander performance.

In principle, you can check yourself:

Go without compilation:


package main

import (
"Log"
"Regexp"
"Time"
)

func main () {
const str = `If I do not get to the bottom, but it's like? More precisely, what compared libraries? not veryu`
const match = `this is (as) \? '

start: = time.Now ()

for i: = 0; i <1000; i ++ {
_, _ = Regexp.MatchString (match, str)
}

log.Printf ( "took:% s", time.Since (start))
}

Go to compilation


package main

import (
"Log"
"Regexp"
"Time"
)

func main () {
const str = `If I do not get to the bottom, but it's like? More precisely, what compared libraries? not veryu`
const match = `this is (as) \? '

start: = time.Now ()

r: = regexp.MustCompile (match)

for i: = 0; i <1000; i ++ {
_ = R.MatchString (str)
}

log.Printf ( "took:% v", time.Since (start) .Seconds ())
}

PHP:


<? Php

$ Str = "If I do not get to the bottom, but that's exactly what the library was compared not believe?";
$ Pattern = "/ it (as) \ / m?";

$ Start = microtime (true);

for ($ i = 0; $ i <1000; $ i ++) {
preg_match ($ pattern, $ str);
}

echo (microtime (true) - $ start). "Secs";


Go without compilation: 0.005807088 seconds
Go to compilation: 0.000459663 seconds
PHP: 0.000177860 seconds

timo-71, скорость работы реализаций на разных языках интересно сравнивать, потому что иногда бывает, что медленный язык в какой-то задаче оказывается быстрее (например регулярки в PHP быстрее чем в Go).

На пыхе кстати можно декодер через yield завернуть, возможно будет быстрее. И можно было бы использовать mmap, если бы он там был.

timo-71, speed implementations in different languages is interesting to compare because sometimes it happens that a slow tongue at some task is quicker (for example, the regular season in PHP faster than Go).

On pyhe way you can wrap the decoder through the yield may be faster. And it was possible to use mmap, if he was there.

VoV@:
Если не грузить сразу в память всё, то ИМХО, только и перебором символов получится.

Ну оно по сути все через перебор символов работает, только можно делать это буферизированно, а можно задалбывать диск и ядро сисколами, читая по 1 байту.

И можно сразу в память все распаковать, а можно читать и по чуть-чуть распаковывать, попутно высвобождая память. У второго подхода как вы понимаете много преимуществ, на слабых машинах можно парсить огромнейшие файлы, можно прервать распаковку на пол пути, если например стоит задача читать до тех пор, пока не найдем нужный нам объект.

За сколько у вас отработал ваш код на данном файле?

VoV @:
If you do not ship directly into the memory of all, IMHO, only brute force and character work.

Well, it is in fact all through the bust of symbols only work you can do is buffered and can drive and zadalbyvat core siskolami reading 1 byte.

And you can just unpack everything in memory, and can read and decompress a little, passing freeing memory. In the second approach, as you can imagine a lot of benefits on low-end machines can parse large files, it is possible to interrupt the decompression half way, if for example the task of reading until until we find the required object.

For how much you have worked for your code to this file?

Sly32, на выходе не валидный json :) Да и вычитано у тебя все в память.

Мое решение на Go, как обычно - самое длинное https://play.golang.org/p/gWg-gqR-Xvi

file filtered successfully, took 22.997923ms
Всего: 1540