Live data from Hacker News

A Very Simple Genetic Algorithm Written in Swift 3

gist.github.com

1–10 of 42 posts

Re: A Very Simple Genetic Algorithm Written in Swift 3

#3

> Note -- this is much slower than the python version Surprising. Swift, a compiled, static language, is slower than python in this use case?

stuff like this can't help

var n = Double(arc4random_uniform(UInt32(weightTotal * 1000000.0))) / 1000000.0

Re: A Very Simple Genetic Algorithm Written in Swift 3

#4

> Note -- this is much slower than the python version Surprising. Swift, a compiled, static language, is slower than python in this use case?

This is just speculation, but slowness might be because this is being run as a script via /usr/bin/swift, rather than being precompiled into a binary.

Certainly I have found my own Swift scripts seem to be a lot slower than compiled programs.

EDIT: from my own test with 1000 iterations, script version 17s, compiled version (release build) 5.4s

Re: A Very Simple Genetic Algorithm Written in Swift 3

#5

> Note -- this is much slower than the python version Surprising. Swift, a compiled, static language, is slower than python in this use case?

stuff like this can't help var n = Double(arc4random_uniform(UInt32(weightTotal * 1000000.0))) / 1000000.0

Yep totally, going to take another pass to try and make it faster. This was just a make it work experiment. Had a few fun troubles with random, but at the moment it just crawls :(.

Re: A Very Simple Genetic Algorithm Written in Swift 3

#6
post #4

> Note -- this is much slower than the python version Surprising. Swift, a compiled, static language, is slower than python in this use case?

This is just speculation, but slowness might be because this is being run as a script via /usr/bin/swift, rather than being precompiled into a binary. Certainly I have found my own Swift scripts seem to be a lot slower than compiled programs. EDIT: from my own test with 1000 iterations, script version 17s, compiled version (release build) 5.4s

ah great point. I'll time it both ways and see where I'm at.

Re: A Very Simple Genetic Algorithm Written in Swift 3

#7
post #4

> Note -- this is much slower than the python version Surprising. Swift, a compiled, static language, is slower than python in this use case?

This is just speculation, but slowness might be because this is being run as a script via /usr/bin/swift, rather than being precompiled into a binary. Certainly I have found my own Swift scripts seem to be a lot slower than compiled programs. EDIT: from my own test with 1000 iterations, script version 17s, compiled version (release build) 5.4s

good stuff. tbh though, only ~3x slowdown in scripting imo is pretty damn good 8)

Re: A Very Simple Genetic Algorithm Written in Swift 3

#9
post #4

Earlier quoted context omitted.

This is just speculation, but slowness might be because this is being run as a script via /usr/bin/swift, rather than being precompiled into a binary. Certainly I have found my own Swift scripts seem to be a lot slower than compiled programs. EDIT: from my own test with 1000 iterations, script version 17s, compiled version (release build) 5.4s

good stuff. tbh though, only ~3x slowdown in scripting imo is pretty damn good 8)

[deleted]
Post reply on HN