Interesting task for programmers

S3 211
#21
Gerga:
Reading flow goes to a certain symbol or length parameter

I think, in your output will be an extra comma at the end of

Avatar 89
#22
Sly32:
I think, in your output will be an extra comma at the end of

No comma is recorded before adding a new entry and after then, as was done 1 record to just failed "[{" and "}]".

Avatar 196
#23
Danforth:
For how much you have worked for your code to this file?

I have from time to time shows a different time, then <= 110ms, then <= 240ms.

---------- Posted 15.06.2020 at 13:41 ----------

Danforth:
you can read and decompress a little, simultaneously freeing up memory.

My code works well.

⭐ Разработка Андроид-приложений (Xamarin C#). ⭐ Разработка ASP.NET (WebForms, MVC, WebAPI, Core). ⭐ Цой жив!
T7 30
#24
DenisVS:
It must be some kind of wrapper, while all running scripts at once (in different languages) to compare.

From the point of view of a scientific experiment, the comparison methodology can, and it makes sense to think about. And in this sense the subject can no longer see. Danforth, won with a margin of 5-10 fold, but he and judging by the GO

func NewDecoderfunc NewDecoder (r io.Reader) * DecoderNewDecoder returns a new decoder that reads from r.The decoder introduces its own buffering and may read data from r beyond the JSON values requested.

streaming parser on board.

And we have here is an example (read 10 times fopen and file_get_contents)

fread ($ handle, 1);

 ---- filesize: 411009 
---- fread len: 1
Timing fopen: 60.1470 ms
Timing file_get_contents: 0.6912 ms
Timing fopen: 62.8970 ms
Timing file_get_contents: 0.3510 ms
Timing fopen: 56.3872 ms
Timing file_get_contents: 0.3788 ms
Timing fopen: 64.8222 ms
Timing file_get_contents: 0.3781 ms
Timing fopen: 59.4339 ms
Timing file_get_contents: 0.3750 ms
Timing fopen: 61.2819 ms
Timing file_get_contents: 0.3550 ms
Timing fopen: 55.8791 ms
Timing file_get_contents: 0.3731 ms
Timing fopen: 61.0499 ms
Timing file_get_contents: 0.3550 ms
Timing fopen: 53.5061 ms
Timing file_get_contents: 0.4139 ms
Timing fopen: 60.6580 ms
Timing file_get_contents: 0.3819 ms

fread ($ handle, 4096);

 ---- filesize: 411009 
---- fread len: 4096
Timing fopen: 0.7210 ms
Timing file_get_contents: 0.5479 ms
Timing fopen: 0.3130 ms
Timing file_get_contents: 0.2179 ms
Timing fopen: 0.2880 ms
Timing file_get_contents: 0.2019 ms
Timing fopen: 0.2718 ms
Timing file_get_contents: 0.2241 ms
Timing fopen: 0.3440 ms
Timing file_get_contents: 0.2580 ms
Timing fopen: 0.3731 ms
Timing file_get_contents: 0.2759 ms
Timing fopen: 0.3359 ms
Timing file_get_contents: 0.2561 ms
Timing fopen: 0.3331 ms
Timing file_get_contents: 0.2730 ms
Timing fopen: 0.3619 ms
Timing file_get_contents: 0.2720 ms
Timing fopen: 0.3259 ms
Timing file_get_contents: 0.2201 ms

But if 4096 or how many are there, the last object is broken and should be such as to save the state. Although too easy just need to sit down.

------summary

And yes, PHP will still lose GO. Even after playing 60 of 140 ~ 80 strongly over 22-x

D 141
#25

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.

Разработка и поддержка высоконагруженных проектов.
HM 208
#26
Danforth:
eg regular season in PHP faster than Go

If I do not get to the bottom, but it's like? More precisely, what compared libraries? I do not believe :)

In php apparently PCRE (or PCRE2?), And go?

D 141
#27

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
HM 208
#28

Danforth, not quite agree with the benchmarks, but thanks for the explanation. Generally I'm not a fan of these threads of here, this is indicative of synthetic solution of problems which, in reality, works differently.

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

D 141
#29
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.

Avatar 256
#30

as for me all the interest of solving problems - an algorithm that is taught at the institute, using languages such as Pascal, in which there is a large of number of built-in functions.

I remember how difficult it was to write a simple task, knowing the basics of railway php, and knowing that php (he loves to write one expert), it takes a couple of lines or call the pair of functions, but these functions you first need to write to

Здесь не могла быть ваша реклама

To post a new comment, please log in or register