Programming Languages

Hello Veeky Forums, I want to learn a new programming language to do fast computations, think computational physics/mathematics/finance.

I already know Python, Matlab and a bit of Java, but they are SHIT SLOW AS BALLS.

I need something fast to solve PDEs, I heard C++ and C are good, what's Veeky Forums opinion?

Other urls found in this thread:

scipy.org/topical-software.html
docs.julialang.org/en/release-0.4/manual/arrays
stackoverflow.com/a/1326084
benchmarksgame.alioth.debian.org/u64q/performance.php?test=mandelbrot
paypal-engineering.com/2013/11/22/node-js-at-paypal/
stackoverflow.com/a/8948901
twitter.com/SFWRedditImages

Assembly

Before you try other languages you may first want to make sure you're actually writing good code.

>If you're handling a lot of data and doing stuff like inserting records, deleting records, sorting records, and searching for records then make sure you're using appropriate data structures (any textbook on algotrithms will cover this in more detail).
>If you're using numeric data in vectors/matrices then you should write vectorized code (if you don't know what this is then look it up). Note, using matrix operations is typically a lot faster than using for loops.

If the above don't give you good results then you may want to try C++ and possibly even C++ Cuda (you write a special type of function called a kernel and that function runs in parallel over a large amount of data on the GPU).

You may also find it easier to just look for a framework or library designed for handling the sort of thing you're trying to do (if one exists). Typically such libraries/frameworks come with functions that are already optimized so that they run reasonably fast.

Assembly is fast but if you're writing your code in a straightforward way then it's still likely to run slower than an algorithm that uses some confusing non-trivial computational tricks.

Also, you can't write GPU code in assembly (NVidia does have an assembly-like language you can code in but it isn't actually assembly) because different GPUs have different instruction sets and given that it's proprietary these companies haven't established any sort of standard (nor should they).

Stuff like asynchronous or parallel code in general is harder to use in assembly.

Depending on what you're doing there may be cases when writing assembly will be faster, but in general when doing computational stuff you're better off writing vectorized code in a library that depends on BLAS and LAPACK.

Why do you think you can implement faster numerics than MatLab?

Yeah, I took an Algorithms and Data Structures class and I make sure all my programs run in O(n), or, for 2 dimensional things in O(n^2).

Still, every time I click "run", it may take a minute before the plot shows up. Also, since every thing I'm gonna be doing from now will only get bigger and bigger, I thought it might be a smart idea to get used to faster languages already now.

>Stuff like asynchronous or parallel code in general
Looks like a job for Rust.

O(n^2) is slow. If you're dealing with two dimensional things then write vectorized code, it will be much faster than O(n^2).

I've seen operations on huge data sets that take a few minutes with vectorized code vs the same operation using loops taking entire days.

I hope you're not writing your own integrator.

Check:
scipy.org/topical-software.html
Crtl+f
partial diff

Above that you have distributed libraries if one of those solvers aren't enough. If you need some kind of weird calculations where you need to implement your integrator use C++.

Rule of thumb is that you should try to make things run in less than O(n^2).
O(n * ln(n)) is fine too.

I like C for lower level programming when I need efficiency and/or control over the hardware.
Else I just use C# or Haskell.

I'm not OP, but nigger please, if you're working with 2D data you can't go below n^2 (outside of tricks like mentioned, but that's not really lowering the complexity and depends on the machine more than on the algorithm) for about anything, unless you don't have to visit every point even once for some reason (like you can go below O(n) for 1D data only in algorithms like binary search that jump around the arrays)

>Else I just use C# or Haskell.
Just curious, if you like Haskell then why not F# instead of C#?

When you write vectorized code you aren't actually doing any tricks. All you're doing is rewriting your code to use stuff like matrix multiplication and other matrix operations instead of for loops.

The idea is that the matrix operations themselves are performed by libraries (like BLAS and LAPACK) that DO have tricks written into them.

Vectorized code is so standard when dealing with data that it's almost bizarre to hear someone say
>I'm not OP, but nigger please, if you're working with 2D data you can't go below n^2
Using for loops to deal with data is unanimously considered bad code.

You should use Rust or Java.
Java isn't as slow as people say, it can be really great and it's simple and good for parallelization if you understand how it works and which objects are thread safe.
Rust is about as fast as C, and it's the best languages when it comes to safety/performance ratio. It's way more safe than C, C++, Java etc. But it's much harder to program. If you are a good programmer you'll love Rust and will be able to do great things with it, but it can be really hard for novice. You have to understand how things works, think before-time about everything and program in a way Rust was intended.

What?
Vectorized code keeps the same complexity, it just makes it constant-times faster.

Of course you can, this is why algorithms exists. For example you can generalize binary search to 2D arrays and get O(log(x)^2) instead of O(x^2).

>Using for loops to deal with data is unanimously considered bad code.
Just use a better language senpai:
docs.julialang.org/en/release-0.4/manual/arrays

"In general, unlike many other technical computing languages, Julia does not expect programs to be written in a vectorized style for performance. Julia’s compiler uses type inference and generates optimized code for scalar array indexing, allowing programs to be written in a style that is convenient and readable, without sacrificing performance, and using less memory at times."

>Java, an interpreted language isn't slow.

Fortran

>2016
>interpreted JVM

Java bytecode is interpreted to machine code by the JVM as the program is executing.

This is totally different from (an implementation of) a language that is compiled directly to machine code like C, C++, Rust, Julia, etc...

stackoverflow.com/a/1326084

Sorry dude, hadn't seen you wrote 2D data. But it's still possible like said.

I prefer Haskell to F#. And when I want to use a .NET library then there are often lots of examples of how to use them with C#.
Never really used .NET interop in F# but I should probably try it out once.

JavaScript also uses a JIT compiler and arguably JavaScript's is much more efficient and has had a lot more work put into it.

At best your argument is
>sometimes Java can run almost as fast as JavaScript.

What the fuck. Javascript was created literally in two weeks. And JIT doesn't mean it'll be as fast as compiled languages, but it means it can be as fast as them. Javascript is weakly typed and is not designed for native execution so it can never be close to C or Rust. Java however is way more similar to them, it's strongly typed and has low level access. Good code with good JVM that supports JIT(most modern do) comes close to them when it comes to speed. Though, it has to be said it uses way more ram.
benchmarksgame.alioth.debian.org/u64q/performance.php?test=mandelbrot
Check other tests as well.

>doesn't know about asm.js

It can be faster than Java. There are actually ports of serious games and game engines to JavaScript. On the other hand, just about the most efficient Java game you'll ever see is minecraft (seriously, what kind of retard writes a game in Java, no wonder his wife divorced him).

Asm.js is an intermediate programming language, you don't write a code in it.
You first need to write code in C++ or other language and compile it to asm.js instead of bytecode. The program is still C++/whatever and not Javascript. Also asm.js is that fast not because Javascript it fast, but because browsers are optimalized for it. Normal Javascript code isn't compatible with asm.js and can't use these features.
Minecraft is far from being efficient. It's getting better, but it's not that easy to clean up Notch's shit.
>It can be faster than Java.
[citation needed]

>I prefer Haskell to F#
Well obviously. But F# is an okay language, and the bottom line is that it can be written like C# with fewer keystrokes if a need arises (some things like WPF are more awkward to use in F#, but then it's not hard to write the main program in it and add some glue code in C#). Nulls coming from C# code (especially when the type was originally defined in F#, as in that case the compiler thinks it can't have null values) can be annoying, but that's about it.

Java runs at worst half as fast as C

Go for C++, fast, OOP and good support for openCL for GPU computations. And since openCL is based of C you won't have to learn two languages.

It's worth to mention that if you go with C++, you should definitely learn modern C++11/14. There is lot's of tutorials and books about older C++ versions which are deprecated and quite different to modern approach.

>ln
>not log_2

yeah
YEAH
YEAH VECTORS
YEAAHH!!!

in my numerical analysis class my teacher talked about how people were trying to get some matrix multiply algorithm below O(n^3) as much as they can.


the teacher was like, "i don't think we'll ever get to O(n^2), but maybe we'll get to O(n^(2 + epsilon)) for some small epsilon.


he was so lame but i love him

numerical methods not numerical analysis my bad

Cuda (NVidia only) is nicer to work in than OpenCL.

>browsers are optimalized for it.
You can code in asm.js it's just awkward and somewhat tedious but there are people who do it (you can find blogs on planet.mozilla.org.
You mean the JIT compilers that browsers use are optimized for it.

So it's just Minecraft that's the exception and not the norm. Are you suggesting that people actually do/should write games in Java!?

>[citation needed]
Node.js is the implementation that people would actually use to replace Java software (because Node.js doesn't have to be run in a browser).

paypal-engineering.com/2013/11/22/node-js-at-paypal/
stackoverflow.com/a/8948901
These are instances that show it can be faster than Java. You can actually find an obscene number of such articles on the internet. This is probably attributed to Node.js' concurrency and the fact that all of the core modules are actually written in C++.

the base of the logarithm doesn't matter in this context

do you divide up your datasets into e parts when you do a search?


this is a shitpost.

Learn C++. You'll also end up learning C in the process.

If those languages are slow for you it most probably means you haven't really learned them to any extent worthy of the claim.

>You can code in asm.js it's just awkward and somewhat tedious but there are people who do it (you can find blogs on planet.mozilla.org.
You can also run native code using JNI in Java and say Java is as fast as assembly. Hell, you can even write weird interpreter for python that will work the same way as asm.js, by making subset of python that can be easily compiled to mashine code. But it won't mean python or java are as fast as assembly. Sure asm.js might be that fast, but normal javascript code isn't.
>So it's just Minecraft that's the exception and not the norm. Are you suggesting that people actually do/should write games in Java!?
There is absolutely nothing wrong in making games in Java. Java is suitable for that, it has all the tools and libraries you would need to make a video game.
Well written games in Java will mostly likely outperform these made in Unity or other game engines.
Also the differences in performance are so insignificant, that quality of your code matter the most. Minecraft was just written by someone who didn't really understood what he was doing.
>paypal-engineering.com/2013/11/22/node-js-at-paypal/
>There’s a disclaimer attached to this data: this is with our frameworks and two of our applications.
>stackoverflow.com/a/8948901
>I wouldn't attribute the speed increase to raw V8 vs. Java 7 performance but rather to the implementation.
Node.js is faster in these tests because they have written better code. It's comparison of their implementations, not languages/compilers/interpreters. Write any non-trival code in Node.js and I'll provide Java code that does the same thing faster.

Only if u a shitty C programmer.

i disagree. i've been doing C++ for a few years and feel proficient, but pure C (gotta at least know for the operating systems course) is frightening.

>People defending Java
>People recommending esoteric language

I want /g/ to leave.

Perl. It's ugly as fuck, but still worth. Rarely used outside science tho

check out julia
id say its exactly what you want

1) Learn C++
2) Learn how to use mex in Matlab which lets you call C++/C/Fortran functions Matlab
3) Learn how to use C++/C code in Python
4) Never touch Java again.

the results from a natural log transform are only a constant multiple of the results from any other log transform. it doesn't matter what base you choose, the results will have the same shape

>
>>Else I just use C# or Haskell.
>Just curious, if you like Haskell then why not F# instead of C#?

One thing C# has that F# doesn't is employment opportunities.