/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?
Old thread:

Other urls found in this thread:

smilebasicsource.com/page?pid=68
doc.rust-lang.org/book/inline-assembly.html
en.wikipedia.org/wiki/Busy_beaver
twitter.com/AnonBabble

First for Haskell generating garbage 1GB/s

I am trying to re-implement getopt() properly.

Currently getopt() sucks in
1. Indexing inputs
2. Multiple flagged inputs

That's 6 GB/s for you :^)

i really like this op image

First for Java is the choice for high performance computing

What is man supposed to use when here's just no good statically typed and compiled language.
>sml
no good implementaion
>ocaml
sml with shitty syntax, also does not support native threads
>lisp
too verbose, also static typing not standardized
>c
decent but manual memory management is annoying in prototyping phase
>sepples
cluster fuck that no sane person would touch
>d
can't decide if it wants to have gc or no
>rust
better stay away from it because it attract lot of crazy hipsters, also uglier than sepples
> any jvm/clr lang
requires HUGE vm
>go
Rob Pike is faggot, also no macros
>haskell
generates garbage 1GB/s
>chapel
uses more memory than java
>nim
lol python like syntax, also buggy

pure asm, platform independent high performance code is a meme

Java

Nobody gives shit about performance.
AST might be decent but the different syntax for manually memory managed stuff and garbage collected stuff seems really annoying.

HUGE VM

>AST
meant ATS

There a lot more than those.

I second this

Java OpenJDK: 1.189619693 seconds time elapsed
C clang: 9.971914301 seconds time elapsed
C++ clang++: 5.518077517 seconds time elapsed
C++ G++: 4.659448453 seconds time elapsed
Python CPython: 77.788729238 seconds time elapsed
Python PyPy: 46.487679095 seconds time elapsed


Thank you for using an anime image.

me too user

if you dont give a shit about performance then who cares about your code being statically typed and compiled

Deploying native executables instead of requiring userbase to install HUGE vm / interpreter.
I prefer static typing to dynamic in big projects because you can detect stupid mistakes in compile phase.

>HUGE VM

Oh wow 50MB whatever will you do without that.

ive got some free time, so right now I'm working on a dubs script, then im gonna try to make a autoheal for this one .io game

I used chromebook with 16gb ssd for year and usually had only few hunded mb free for additional programs so jvm was no no. Also the trend seems to be smaller devices with 32/64 gb ssd and when most of that space is filled by 100mb web apps making your applications space efficient matters.

is this better now?
|0000000|00000|00000|0|00|0|000000|00000|
|opcode | re1 | re2 |0|00|i| fun | re3 | integer register

|0000000|00000|00000000|1|000000|00000|
|opcode | re1 | litr |i| fun | re3 | integer literal

|0000000|00000|00000|0000000000|00000|
|opcode | re1 | re2 | function | re3 | flaot

|0000000|00000|00000|000000000000000|
|opcode | re1 | re2 | displacement | memory

|0000000|00000|000000000000000000000|
|opcode | re1 | displacement | branch

That's a big number.

No that is absolutely not the trend you pleeb

What were the compiler options for C and C++?
I'm guessing that part of the reason C and C++ perform worse is O0.

people using laptops with max 128gb ssd where windows takes 30 of it already.
It's delusional to think that "people have enough space" dumb nigger.

>98GB free, but no space for 50MB

>he doesn't have 90gb of pictures
You clearly have never seen how poorly people manage space dumb frog poster.

>he just makes up random nonsense to prove his point

You clearly are a buffoon so I say good day to you and stay out of our java territory which is this entire board because this is a java board now so you better like java

Pajeet...

It's too late to stop us now. Our forces are moving into the board.

We have 300 million people of fighting age and that's not even including teenagers who could easily be drafted as child soldiers or people older than 40 who could still fight for the motherland.

Surrender and accept the rule of java or face death.

go shitpost elsewhere nigger.

Uh what did you just say to me paleboy? I'll have you lashed if you do that again.

im working on a ncurses Sup Forums client

i have reached a new autistic high in my life

Lua > Python >>> JavaScript

You better switch over to java or else we'll send the secret police round

>find a perfect language
>it's either dead or has incompatible versions

Tried it out myself. Using Measure-Command in powershell to benchmark.

C version compiled with GCC -O2:
4172.3 ms
Java version:
4382.8 ms

What is the best programming language and why is it not cinnameg?

What's the most autistic thing you've recently seen?

smilebasicsource.com/page?pid=68
Brainfuck compiler to Smile Basic for the 3DS.

Wow even with tough optimisations and hours of meticulous hand crafting C can only just scrape victory over mighty java.

Truly what hope can you have for a C victory against the might of the orange army?

>try to start project
>this should be easy
>realise you are shit at programming

Well fuck

Try python instead, it allows everything to work even when it doesn't make sense.

Until you're ready to work with java like a true jarvyan you'll have to stay in the python camp though.

I tried this test with Java, C++, and Rust. The source code for the C++ and Java versions are identical to what you have provided. The Rust version looks like this:

pub fn main() {
let mut n : i32 = 0;
for i in 1..2000000000 {
if i % 3 == 0 && i % 5 == 0 {
n += 1;
}
}
println!("{}", n);
}

I compiled Java using the Oracle Java9 compiler, and tested with the Oracle Java9 VM. The result was a time of approximately 2.83 seconds, both with and without -XX:+AggressiveOpts. For C++, I used g++ 5.4.1 with the -O3 flag, and produced an average runtime of 1.99 seconds. For Rust, I unfortunately have an outdated compiler (rustc 1.7.0, which is what I can get through the Ubuntu 16.04 package manager. I need to get something better via Rustup or something). I compiled with -C opt-level=3, and produced an average runtime of 5.49 seconds. All three of these are on a laptop with Ubuntu 16.04 and a Core i7 6700HQ CPU.

The sizes of the binaries after stripping are as follows:

Test.class: 467 bytes
TestCPP: 6344 bytes
TestRust: 327208 bytes

Conclusion: C++ is a clear winner for speed. Java is better for binary sizes, but this is to be expected from bytecode languages. I will need to test Rust again with a more up to date compiler.

I know that the benchmark itself is trolly shit, but calculating the number of ints divisible by 3 and 5 in O(n) gives me fucking aids.

It is, yes. The point of the benchmark, I think, is to show off how Java does in nested loops. The problem with this as a benchmark is that it's the only area where Java does even remotely well.

Garbage > Vomit >>> Diarrhea

>literally just o2

What's the deal with HPC languages like x10, fortress, zpl and chapel?
Are they fit for general purpose programming are they only usable on for distributed systems with at least 128 cores?

>pub fn main()
Why.
What the fuck is the purpose for this.
It makes everything 12 times as hard to read and doesnt save any kind of space.

I use python at work all the time, but it's just for scripts. Least trivial project I've ever done is build a good scraper for LinkedIn, I've never collaborated on a big piece of software.

I'm learning C atm too.

How do I get gud?

Because the creators of Rust preferred shorter keywords. Doesn't make it much harder to read, IMO.

Invest _serious_ amount of time, and emply a healthy amount of self criticizing and you'll be good one day.

Dont be afraid of code review, try reviewing other peoples code, aswell as getting your code reviewed by someone who knows shit.

I've just tried the java one and got 2.4 seconds average for normal and 2.2 by running it through proguard for extra optimisations.

Ultimately, there's not really a big difference in performance. I'd like to see it with python though, I bet that's really horribly slow.

>comparing the performance of a single for loop
>he even compared the binary file size
low quality bait.

Come on then, design a performance test for me to run.

>I'd like to see it with python though
2 minutes and counting at 100% CPU

Holy shit, you fucking retard whoever posted this.
I woke up after the thread had died so I have to reply here.

Rust supports inline assembly in the same way that C supports it, it's just as easy to use and it uses the same syntax.
doc.rust-lang.org/book/inline-assembly.html

The only difference, is that in Rust, it's actually standard (minus the actual assembly instructions) unlike in C.

Ouch

In case this wasn't sarcasm:
Java does have the potential to perform well. But it doesn't come for free. C is the same. The difference is in where you put your effort. In Java you have to write code in very peculiar ways and configure your JVM meticulously. In C you have to think about all these low level concerns you might have.

There's some interesting aspects to the Java way a lot of optimization can be done on user machines by configuring your JVM on the fly and asking a server for appropriate settings (for instance). With C that'd be way harder.

So if you actually don't know your platform Java probably wins out for a dedicated developer.
>Test.class: 467 bytes
>TestCPP: 6344 bytes
>TestRust: 327208 bytes
You're forgetting the JVM. It either needs to be installed or packed with the executable.
If you wanted a fair comparison you should look at a CPP where you have dynamic libraries for your standard entry point and standard library in general. Or you could add the jvm to the test.class size.

Also tried Rust:

¨fn main() {
let mut n = 0i32;
let mut i = 1i32;
while {i

i'm not interested in designing performance tests. why do i need to explain to you that comparing the performance of a simple, single loop is stupid?

Try clang.

Calculate BB(10).

rubyist@Overmind:~/cs/scratch/benchmark$ time ./Py3Test.py
133333333

real 4m38.203s
user 4m38.064s
sys 0m0.048s
rubyist@Overmind:~/cs/scratch/benchmark$ cat Py3Test.py
#!/usr/bin/env python3

n = 0
for i in range(1, 2000000001):
if (i % 3 == 0 and i % 5 == 0):
n += 1

print(str(n))

Gonna test Ruby next.

poojeet

>design a performance test for me to run.
user the best performance tests are real world examples.
It's a lot of work though. But you can look to compare different open source software solutions for problems and compare the performance of the C and Java solutions and consider the effort that was put into it. That's a shortcut. It might take a day or two but you will come out wiser.

???

rubyist@Overmind:~/cs/scratch/benchmark$ time ./RubyTest.rb
133333333

real 2m11.256s
user 2m10.872s
sys 0m0.020s
rubyist@Overmind:~/cs/scratch/benchmark$ cat RubyTest.rb
#!/usr/bin/env ruby

n = 0
for i in 1..2000000000
if i % 3 == 0 && i % 5 == 0 then
n += 1
end
end

puts n

Literally half the time of Python.

>What are you working on, Sup Forums?

reading K&R 2nd edition to make a toylang

By the way, I really want to make a toy language but with a big fat stdlib by relying on another language. I was thinking of embedding python in the generated C code (with lots of cool pypi modules) and implement them in C as I find stuff that needs more performance

>doesn't know what the Busy Beaver function is
en.wikipedia.org/wiki/Busy_beaver
How's that education going for you, Ranjeet?

That isn't making anything, that already exists

>doesn't know what is

Oh no whatever will I do without

I don't understand what is supposed to be so difficult about this problem. Isn't it just:
void busybeaver(unsigned char const* address, int size) {
for (; size > 0; size--, address++) *address = 0xff;
}

Am I the only one underwhelmed by all of this?
Why doesn't the compiler do this at compiletime?
Most compilers aren't even competently multithreaded. This is the perfect kind of workload. It's easy to prove that no input can affect the result so just run it. Set a cap on the number of CPU ticks you can waste if you're concerned about halting. Send a warning to the user that they failed to optimize it and cache the result for next compilation.
The user was asking for -O2. Why is it not optimizing?

C# it is

>niche
>one of the most famous examples of a non-computable function that any undergrad who has enough brain cells to be able to take an intro to complexity course would encounter
This Pajeet damage control is just hilarious.

shit why did i put const there

>CLR
It was covered.

you what... why isn't everyone using the same programming language then, seeing as most mainstream ones (and even niche ones like haskell) mostly have every single thing you might want already implemented in some library?

>C/C++ bloated
>test.class only 463 bytes
you forgot to add the 6000 kb for the java virtual machine

That would still add up to less than the others

>rubyist@Overmind
>not root@ambrozia

what the fuck is this meme about needing some huge ass virtual machine to run java? java compiles to native bytecode you absolute retards

>native
>bytecode

yup, java pajeet, makes sense

Compiler isn't going to evaluate a large enough loop, as long compile times are not desirable. It also isn't smart enough to know that it could solve the entire problem in a single div instruction. Hence, it generates the loop, but does regular optimizations, like converting division into other instructions.

>6000kB+x bytecode
Sure, Java can compile to a binary for the platform. Most languages have something like that. What's being compared is the more normal running modes.

you know what i mean. point is, .class files are just executable files like any other, they consist of machine instructions for whatever processor you compiled on and don't require any virtual machine to run

>as long compile times are not desirable
Every compiler should have a flag that tells it I don't care about this.
But it's very annoying to have a program that can be run in less than 10 seconds be compiled into such an inefficient piece of code.

Just also tried it in the Julia repl:
function main()
n = 0
for i = 1:2000000000
if (i%3==0 && i%5==0) n = n + 1
end
print(n)
end


Running this in the repl with the @time macro gives me 3879 ms

So faster than C/Java/Rust, despite the fact that the language is dynamic, and that this includes the jit compilation time. I'm spooked.

Python has no excuse whatsoever to take several minutes to finish this task.

>.class files are just executable files like any other
Rename it and run it.
Protip:
Doesn't work like that.

What? C was doing it in less than 2 and java was doing it in 2.2. 3.9 is nowhere near

what's so difficult about 1-filling a bitfield

I quoted my earlier tests on the same machine. Can't tell if troll or retard.

...

Well then you're a lyin bastard because that's clearly interpreter propaganda

I wonder how you could write a compiler that knows to optimise things like that where a loop isn't really needed.

most compilers will optimize away loops like
for (int i = 0; i < 100000000000; i++) {}

It's not particularly hard. It's just that cases like these aren't a big concern.

I know that but I mean like calculations that can be done in one step instead of by going through every number in a loop

Also if you are copypasting this it should have "end" at the end of the inline if.

All hail the LLVM JIT. That thing is a beast.

Friendly reminder that Rust is actually lighter weight than both C and C++.