Skip to content

Instantly share code, notes, and snippets.

View python_datetime_attributes.csv
class Attributes
date year, month, day
time hour, minute, second, microsecond, tzinfo
datetime year, month, day, hour, minute, second, microsecond, tzinfo
View python_file_open_mode.csv
mode read write create truncate cursor position
r * start
w * * * start
a * * end
r+ * * start
w+ * * * * start
a+ * * * end
x * start
View python_read_write_cheat_sheet.csv
method/keyword parameters uses
open() filename and open mode (optional) create a file object by opening/creating the file in the specified read/write mode
with - use it together with open(); closes the file after the suite completes
read() size (optional) read the file up to the size specified if set
readline() size (optional) read a single line with a size limit if set
readlines() size (optional) create a list of the read lines with an optional size hint
for loop - iterate the lines of the file
write() the string write the string to the file that is opened with a certain writeable mode
writelines() the list of strings write the list of strings to the file that is opened with a certain writeable mode
close() - close the opened file
View swift_array_set_comparison.csv
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.
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.
View swift_array_set_function.swift
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
View swift_array_set_stats.py
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:
View swift_array_set_experiments.swift
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]
View swift_array_empty.csv
Element Type Element Number count == 0 isEmpty
Int 0 92.98 78.63
Int 1 76.66 79.90
Int 10 76.92 78.67
Int 100 76.04 77.78
Int 1000 74.46 78.05
Int 10000 78.50 79.11
Int 100000 75.58 78.18
Int 1000000 75.15 77.57
Int 10000000 76.12 79.11
View swift_array_empty.swift
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()
View swift_link_preview_data.swift