Earlier quoted context omitted.
I compiled it down and did a quick profile. Looks like a lot of the time is spent on line 96, converting a Character to its ascii value. https://dl.dropboxusercontent.com/u/13740348/Screen%20Shot%2...
That's because Character is very, very different from ASCII in Swift (a character in Swift holds an extended grapheme cluster. See https://developer.apple.com/reference/swift/character ). I also doubt the way they compute its ASCII value is optimal: extension Character { var asciiValue: UInt32? { return String(self) .unicodeScalars .filter{$0.isASCII} .first? .value } } Certainly if it is optimal, but probably also i…
A Very Simple Genetic Algorithm Written in Swift 3
31–40 of 42 posts
Re: A Very Simple Genetic Algorithm Written in Swift 3
#32Re: A Very Simple Genetic Algorithm Written in Swift 3
#33Re: A Very Simple Genetic Algorithm Written in Swift 3
#34Re: A Very Simple Genetic Algorithm Written in Swift 3
#35Earlier quoted context omitted.
My guess it is all of the string converting back and forth to character arrays.
Yep, replaced string with Int array and now it is much faster. https://gist.github.com/rookie/3d9a848c6fefacc4254da921da79b... It now runs faster (when compiled, optimized) than the python code. xcrun -sdk macosx swiftc -O gen.swift
Re: A Very Simple Genetic Algorithm Written in Swift 3
#36Earlier quoted context omitted.
Isn't the "scripting" part just automatically compiling behind the scenes before running? It's not an interpreter or a VM. So the code runs just as fast as the compiled version, it's just that you pay a startup cost.
That's true between a debug build and just running it as a script I believe. But a release version will be optimized, I imagine if they compared a debug build to the scripted version they'd perform similarly.
Re: A Very Simple Genetic Algorithm Written in Swift 3
#37I thought this was going to be a link to [1], from a talk given at Swift Summit a couple days ago. I haven't really looked at the code for either one to compare them, but for people who are interested, here's a second simple genetic algorithm in Swift (found in RubikSwift/GeneticsSolver.swift) https://github.com/JaviSoto/RubikSwift
Swift looks a lot like Typescript. This is the first time I've read swift code and I'm taken by surprise by its elegance. I'm gonna give it a shot
Re: A Very Simple Genetic Algorithm Written in Swift 3
#38I thought this was going to be a link to [1], from a talk given at Swift Summit a couple days ago. I haven't really looked at the code for either one to compare them, but for people who are interested, here's a second simple genetic algorithm in Swift (found in RubikSwift/GeneticsSolver.swift) https://github.com/JaviSoto/RubikSwift
Swift looks a lot like Typescript. This is the first time I've read swift code and I'm taken by surprise by its elegance. I'm gonna give it a shot
But i'm 100% certain it's going to be one of the most used language server side in the coming years.
Re: A Very Simple Genetic Algorithm Written in Swift 3
#39> let POP_SIZE = 50 c'mon everyone knows genetic population is 30 (I kid I kid but that number has an interesting story https://statswithcats.wordpress.com/2010/07/11/30-samples-st... )
It's not the population size, but the number of times you run the evolutionary algorithm with different seeds.
Re: A Very Simple Genetic Algorithm Written in Swift 3
#40Earlier quoted context omitted.
That's true between a debug build and just running it as a script I believe. But a release version will be optimized, I imagine if they compared a debug build to the scripted version they'd perform similarly.
Can confirm, Debug build runs in similar time to script.
That allows for more aggressive code specialization and inlining and can remove more reference count updates (https://swift.org/blog/whole-module-optimizations/)