This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var records = [(String, Double, Double)]() | |
func compareOperations(name: String, repeats: Int, operations: [()->()]) { | |
var record = (name, 0.0, 0.0) | |
for (index, opertion) in operations.enumerated() { | |
let startTime = CFAbsoluteTimeGetCurrent() | |
for _ in 1...repeats { | |
opertion() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let articleURLs = [ | |
"https://medium.com/better-programming/10-awesome-javascript-libraries-for-front-end-developers-in-2020-d450b9ed66d1", | |
"https://medium.com/better-programming/d3-responsive-and-dynamic-visualizations-for-data-and-other-easy-recipes-68e37b451822", | |
"https://medium.com/better-programming/build-reusable-swiftui-component-libraries-with-the-swift-package-manager-23343681a8f3", | |
"https://medium.com/better-programming/my-one-tip-to-be-effective-at-learning-a-new-programming-language-45789bacf730", | |
"https://medium.com/better-programming/build-a-react-app-using-aws-amplify-in-simple-steps-part-3-12c1b7746450", | |
"https://medium.com/better-programming/convert-json-to-xlsx-file-in-javascript-e7611a975916", | |
"https://medium.com/better-programming/how-to-set-up-a-local-dynamodb-in-a-docker-container-and-perform-the-basic-putitem-getitem-38958237b968", | |
"https://medium.com/better-programming/introduction-to-waitress-a-wsgi-server-for-python-2-and-3-c77e20cb292b", | |
"https://m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticleFetcher: ObservableObject { | |
@Published var article: Article | |
init(article: Article){ | |
self.article = article | |
getArticleWithURL(article.id) | |
} | |
func getArticleWithURL(_ url: String) { | |
let linkPreview = SwiftLinkPreview() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RoundedCorners: Shape { | |
var topLeft: CGFloat = 0.0 | |
var topRight: CGFloat = 0.0 | |
var bottomLeft: CGFloat = 0.0 | |
var bottomRight: CGFloat = 0.0 | |
func path(in rect: CGRect) -> Path { | |
var path = Path() | |
let width = rect.width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var articles = Article.sampleArticles() | |
var body: some View { | |
List(articles) { article in | |
ArticleRow(article: article) | |
} | |
} | |
} | |
struct ArticleRow: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var comparisonRecords = [(String, Int, Double, Double)]() | |
let trials = 10 | |
func compareOperations(name: String, repeats: Int, arrayOperation: ()->(), setOperation: ()->()) { | |
for trial in 1...trials { | |
let arrayStartTime = CFAbsoluteTimeGetCurrent() | |
for _ in 1...repeats { | |
arrayOperation() | |
} | |
let arrayTimeInterval = (CFAbsoluteTimeGetCurrent() - arrayStartTime)*1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from scipy.stats import ttest_ind | |
with open('array_set.txt', 'r') as file: | |
data_text = file.read() | |
splitted = data_text.strip('[(').strip(')]').strip(')]\n').split('), (') | |
data_list = [] | |
for record in splitted: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compareOperations(name: "Initialization Without Elements", repeats: 10000, arrayOperation: { | |
let _ : [Int] = [] | |
}) { | |
let _ : Set<Int> = [] | |
} | |
compareOperations(name: "Initialization With Elements", repeats: 10000, arrayOperation: { | |
let _ : [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] | |
}) { | |
let _ : Set<Int> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] |
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 6 columns, instead of 5. in line 9.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number, Experiment, Array_Time, Set_Time, t_value, p_value | |
1, "Initialization Without Elements", 7.540121674537659, 7.916748523712158, -3.457562191664637, 0.003846372791488026 | |
2,"Initialization With Elements", 8.958488702774048, 24.988874793052673, -49.77387985600688, 3.71485625191658e-17 | |
3,"Iterate Elements", 337.66061067581177, 44.00688409805298, 21.476253166244224, 4.086700260362606e-12 | |
4,"Count Elements", 8.78673791885376, 8.702144026756287, 0.5112195802639851, 0.6171643091164576 | |
5,"Check If Empty", 9.673908352851868, 9.035870432853699, 3.3699231118055515, 0.004578823247822731 | |
6,"Check If Element Exists (When True)", 44.153839349746704, 9.419366717338562, 17.398721378711933, 7.04543940804122e-11 | |
7,"Check If Element Exists (When False)", 357.1058511734009, 9.227603673934937, 44.28782375256025, 1.8869990362188217e-16 | |
8,"Find Element Index (When Found)", 38.447365164756775, 9.576007723808289, 38.59760754000621, 1.2750267004908994e-15 | |
9,"Find Element Index (When nil)", 276.5122652053833, 9.49104130268097, 75. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operation | Performance (> means shorter time) | |
---|---|---|
Initilization | Array > Set | |
Iteration | Set > Array | |
Count | Set = Array | |
Check Empty | Set = Array | |
Find Element Existence or Index | Set > Array | |
Find Min & Max | Set > Array | |
Sort Elements | Set = Array | |
Add Element | Set = Array | |
Remove Element(s) | Set = Array |