News for hackers. Stuff that matters.
Re:Swift Programming Language Evolution by matt4077 on Monday May 09, 2016 @11:07AM (#11660355)
I'd put Go at the top of the languages to compare it to. Maybe Java as well. The ecosystem still needs some time, but Swift's potential on the server is excellent:

- It is incredibly fast compared to current interpreted languages (i. e. factor 30+ vs. Python, possibly faster than C)

- Linux & OS X, open source

- Typed, safe

People like node.js mostly b/c it allows some code to be written once and run on both the server as well as the client. Considering almost any Web API also has an IOS client, Swift has the same potential.

Re:Swift Programming Language Evolution by mirsadm on Monday May 09, 2016 @11:31AM (#11660552)
Every new language has someone claim it's faster than C. I'll believe it when I see it.
Re:Swift Programming Language Evolution by coldtea on Monday May 09, 2016 @11:52AM (#11660737)
Lots of languages ARE faster than C, including older languages than C, like Fortran and Forth.

Being faster than C is not anything special in itself.

Most things being equal (typed, optimized, compiled, no runtime etc) C is mostly faster when it does something with a lower overhead than some other language (e.g. a specially written hashmap algorithm targeted to some program vs C++ std map type), not because of its primitives being faster.

Re:Swift Programming Language Evolution by protomyth on Monday May 09, 2016 @11:56AM (#11660773)
Fortran especially. Forth seems to depend on processor characteristics. I seem to remember that Ada compilers routinely produce faster code than C compilers.
Re:Swift Programming Language Evolution by snuxoll on Monday May 09, 2016 @12:00PM (#11660814)
C has very loose semantics that make it difficult for a compiler to reason about code, as the saying goes, C is often little more than portable assembly. There's a reason that CLion was a big deal when JetBrains announced it, reasoning about C/C++ code is HARD.
Re:Swift Programming Language Evolution by protomyth on Monday May 09, 2016 @12:39PM (#11661134)
If I wasn't more interested in Agent oriented languages, it might be interesting to see what could be done to design a new language built for performance. I would imagine you'd start with the Ada side of the house and work your way back to more pleasing syntax.
Re:Swift Programming Language Evolution by PeCaN on Monday May 09, 2016 @03:19PM (#11662379)
Ada and Rust are both significantly easier to perform aliasing analysis on, so frequently you can get much better code. Both languages have slight overhead for bounds checking and such, but you can turn it off (at least in Ada) if it's a problem (hint: it isn't).

Same reason Fortran is fast actually: it just disallows pointer aliasing entirely¹, meaning you get none of the flexibility of C pointers (heck, you don't even have pointers, basically), but if you're multiplying matrices it flies.

¹ I recall newer Fortrans have pointers, but as I'm not a Fortran programmer I don't actually know.

Re:Swift Programming Language Evolution by steveklabnik on Monday May 09, 2016 @03:54PM (#11662629)
You can call get_unchecked() instead of [] to elide the bounds checking at any place that does it in Rust.
Re:Swift Programming Language Evolution by mirsadm on Tuesday May 10, 2016 @05:31AM (#11666025)
As someone mentioned below, C can almost be seen as a portable assembly. Given enough time and optimization it will always be as fast as the hardware allows. I guess my point was it is meaningless to say "faster than C" because it always depends on too many factors.
Re:Swift Programming Language Evolution by pjmlp on Monday May 09, 2016 @12:46PM (#11661196)
C used to be very slow for 8 and 16 bit home micros to the point hobby Assembly coders could write much better code.

It arrived where it is today thanks to 40 years of research and exploring UB in optimizations.

Re:Swift Programming Language Evolution by lucian1900 on Monday May 09, 2016 @12:31PM (#11661063)
Both C++ and Rust beat C in many cases for various reasons.
Re:Swift Programming Language Evolution by lorenzhs on Monday May 09, 2016 @11:16AM (#11660432)
Do you have a link to some benchmarks at hand? Your "possibly faster than C" claim sounds too good to be true without a source, but I'd very much like to be proven wrong :)
Re:Swift Programming Language Evolution by thomasahle on Monday May 09, 2016 @11:40AM (#11660623)
By http://benchmarksgame.alioth.debian.org/u64q/which-programs-... Swift's performance is similar to Java's, but quite a bit faster when working with many objects: http://benchmarksgame.alioth.debian.org/u64q/swift.html On a few benchmarks it's faster than C as well: http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... though not most.

I suppose they were able to do the binary-tree benchmark so much better than Java, because Swift supports 'UnsafeMutablePointers': http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...

Edit: This Quora question mentions the performance of Swift before and after unsafe programs were included: https://www.quora.com/In-terms-of-performance-speed-is-Swift... The memory safe version used to be about 24x slower than C.

Re:Swift Programming Language Evolution by kzaher on Monday May 09, 2016 @12:18PM (#11660940)
I don't think these benchmarks are realistic. Yes, you can use UnsafePointers, but that's not the real world case. ARC, runtime generics and structs have a huge cost in real world programs.

Swift is unfortunatelly usually an order of magnitude slower then Java and C# in real world according to last benchmarks I've made. I'm hoping that will change because I really love Swift.

Re:Swift Programming Language Evolution by igouy on Monday May 09, 2016 @01:48PM (#11661681)
Please contribute Swift programs that you think are "the real world case":

http://benchmarksgame.alioth.debian.org/play.html

Re:Swift Programming Language Evolution by hellofunk on Monday May 09, 2016 @01:07PM (#11661355)
Agreed. Swift is quite high-level compared to C or C++, for examples. As with any languages, there are tradeoffs with performance.
Re:Swift Programming Language Evolution by igouy on Monday May 09, 2016 @12:14PM (#11660907)
>> I suppose they were able to do the binary-tree benchmark so much better than Java, because

… because it's faster to use a memory pool than GC for that … ditto C Rust Ada Fortran C++ …

http://benchmarksgame.alioth.debian.org/u64q/performance.php...

Re:Swift Programming Language Evolution by igouy on Monday May 09, 2016 @01:46PM (#11661660)
>> Edit: This Quora question mentions the performance of Swift before and after unsafe programs were included

That Quora answer makes claims which are not true.

The Swift benchmarks game programs were always compiled with -Ounchecked (since Dec 7 2015).

The before was naive transliterations (from other programming languages) of single-core programs -- just to demonstrate that Swift was installed.

The after was someone doing the work and contributing programs written for Swift and written for multi-core.

Re:Swift Programming Language Evolution by Sean1708 on Monday May 09, 2016 @11:57AM (#11660779)
Obviously keep in mind the various caveats that come with benchmarks, but it seems that Swift is at least capable of achieving C-like performance[1] in some circumstances.

[1]: https://benchmarksgame.alioth.debian.org/u64q/compare.php?la...

Re:Swift Programming Language Evolution by matt4077 on Monday May 09, 2016 @12:19PM (#11660956)
See https://gist.github.com/MatthiasWinkelmann/d1f19a11d539e609f... for something quick&dirty.

Note that I don't want to claim that Swift is faster than C in general/real life/anything but a few microbenchmarks. But the two just being within an order of magnitude makes a really strong case for Swift, I believe.

Re:Swift Programming Language Evolution by riyadparvez on Monday May 09, 2016 @02:54PM (#11662174)
A bit of justification would be nice why you think Swift can be faster than C.