Earlier quoted context omitted.
Out of curiosity, I gave it a shot. I came out roughly 20% faster using python's inbuilt csv library. When I switched to pypy the csv library actually made it nearly 2x slower than pypy using .split(delim)
And you were using the pure Python CSV library, not the C one?
Faster Command Line Tools in D
91–100 of 100 posts
Re: Faster Command Line Tools in D
#92"The task is to sum the values for each key and print the key with the largest sum." What is the smart way to do this in kdb+? This is my naive, sloppy 15min approach. Warning: Noob. May offend experienced k programmers. k)`t insert+:`k`v!("CI";"\t")0:`:tsvfile k)f:{select (*:k),(sum v) from t where k=x} k)a:f["A"] k)b:f["B"] k)c:f["C"] k)select k from a,b,c where v=(max v)
Using the file from the original, 1#desc sum each group (!/) (" II";"\t") 0: `:tsvfile Took about 3 seconds, 2.5 of which was reading the file EDIT: q)\ts d: (!/) (" II";"\t") 0: `:tsvfile 2489 134218576 q)\ts 1#desc sum each group d 486 253055104
A 4
B 5
B 8
C 9
A 6
How to solve with only a dict?Regarding the 1gram file at https://storage.googleapis.com/books/ngrams/books/googlebook...
This is the result I got
3| 1742563279
using q)\ts d:(!/)(" II";"\t")0:`:1gram
q)\ts 1#desc sum each group d
1897 134218176
371 238872864
or k)\ts d:(!/)(" II";"\t")0:`:1gram
k)\ts desc:{$[99h=@x;(!x)[i]!r i:>r:. x;0h>@x;'`rank;x@>x]}
k)\ts 1#desc (sum'=:d)
1897 134218176
0 3152
372 238872864
No doubt I must be doing some things wrong.Re: Faster Command Line Tools in D
#93Earlier quoted context omitted.
So do Java, C#, Python, Ruby, PHP, Javascript, and virtually everything else and they are very heavily used. Garbage collection is a smashing success in the real world and D made the right decision to follow that success. Of course, it is also true that much of the standard library doesn't actually use it... but these objections are never actually about facts.
None of those languages you listed are for systems programming, which is the one niche you need to excel at if you want to replace C and C++. People who care about that stuff tend to care a lot about managing memory.
Re: Faster Command Line Tools in D
#94Earlier quoted context omitted.
--pipe is well know for being slow. Try --pipe-part instead: parallel -a ngrams.tsv --pipe-part --block -1 awk -f map.awk | awk -f reduce.awk
Thanks for the tip, always nice to see the author of tools commenting on hn :-) The (old) version of parallel packaged with Ubuntu 16.04 (linux subsystem for windows) - doesn't have --pipe-part -- but running from upstream, the speed is more reasonable: $ time (./parallel-20170522/src/parallel -a ngrams.tsv \ --pipe-part --block -1 -j4 mawk -f map.awk \ | mawk -f reduce.awk ) max_key: 2006 sum: 22569013 real 0m2.265s…
Re: Faster Command Line Tools in D
#95Just FYI, I tried using a couple of the pre-compiled binaries in bash on Ubuntu on Windows and got a segmentation fault. Same binaries worked fine in real Linux.
I wonder if that's a WSL bug you should report. Edit: do you mean the tsv utilities? Because they're working fine here on the Creator's Update.
Re: Faster Command Line Tools in D
#96Re: Faster Command Line Tools in D
#97Earlier quoted context omitted.
Using the file from the original, 1#desc sum each group (!/) (" II";"\t") 0: `:tsvfile Took about 3 seconds, 2.5 of which was reading the file EDIT: q)\ts d: (!/) (" II";"\t") 0: `:tsvfile 2489 134218576 q)\ts 1#desc sum each group d 486 253055104
I was using the first example with a char in the first column. A 4 B 5 B 8 C 9 A 6 How to solve with only a dict? Regarding the 1gram file at https://storage.googleapis.com/books/ngrams/books/googlebook... This is the result I got 3| 1742563279 using q)\ts d:(!/)(" II";"\t")0:`:1gram q)\ts 1#desc sum each group d 1897 134218176 371 238872864 or k)\ts d:(!/)(" II";"\t")0:`:1gram k)\ts desc:{$[99h=@x;(!x)[i]!r i:>r:. x…
With the reverse thrown in to switch the key/value around we get the correct answer
q) 1#desc sum each group (!/) reverse (" II";"\t")0:`:1gram
2006| 22569013
or k) {(&x=|/x)#x}@+/'=:!/|(" II";"\t")0:`:1gram
(,2006i)!,22569013i
Works the same for the simple example k)e: 4 5 8 9 6!"ABBCA"
k){(&x=|/x)#x}@+/'=:e
(,"B")!,13Re: Faster Command Line Tools in D
#98Earlier quoted context omitted.
Simplicity and consistency is the biggest strength of Go. D is a complicated language with a ton of features. That makes it harder to learn, and it makes it more likely that you'll encounter "cleverness" in other people's code. As a tiny nit, it's interesting to compare D's `out` keyword to Go's multiple return values. An `out` keyword seems like a prime example of "thinking in blub."
I find that kind of ironic. I know there's a lot of people that love Go and it's a solid language, but I personally see it as the ultimate blub language.
Re: Faster Command Line Tools in D
#99Earlier quoted context omitted.
None of those languages you listed are for systems programming, which is the one niche you need to excel at if you want to replace C and C++. People who care about that stuff tend to care a lot about managing memory.
Ds GC can be turned off to do systems programming.
Re: Faster Command Line Tools in D
#100Earlier quoted context omitted.
The other strength that Go has over D is that Go, being used by Googlers, is much more likely to have better networking support. Two examples come to mind: HTTP2 support (Go was used for either the first or second implementation of that and has standard library support), and TLS cryptography, where Go has it's own suite written by experts, where a good portion of the non Microsoft ecosystem relies on OpenSSL. For web…
In other words, it's because Go has the backing of a huge software company, while D doesn't.