View profile_decorator.py
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 cProfile | |
from random import choice | |
def profiler(func): | |
def wrapper(*args, **kwargs): | |
with cProfile.Profile() as pr: | |
result = func(*args, **kwargs) | |
pr.print_stats() | |
return result |
View fib_inline_prof.py
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 cProfile | |
def fib(n): | |
if n < 2: | |
return n | |
return fib(n - 1) + fib(n - 2) | |
cProfile.run("fib(35)") |
View fib_prof.py
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
29860705 function calls (3 primitive calls) in 5.973 seconds | |
Ordered by: standard name | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.000 0.000 5.973 5.973 profiling.py:1(<module>) | |
29860703/1 5.973 0.000 5.973 5.973 profiling.py:1(fib) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} |
View fib.py
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
def fib(n): | |
if n < 2: | |
return n | |
return fib(n - 1) + fib(n - 2) | |
fib(35) |
View optimised_struct.go
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
package main | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
type OptimisedPost struct { | |
title string // 16 Bytes | |
content string // 16 Bytes |
View unoptimised_struct.go
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
package main | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
type Post struct { | |
published bool // 1 byte | |
title string // 16 Bytes |
View struct_mem1.go
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
package main | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
type MemoryExample struct { | |
a int // 8 byte | |
b int16 // 2 bytes |
View unmarshal_users_array.go
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
func main() { | |
var users []User | |
userJson := []byte(`[{"firstName": "Lachlan", "surname": "Eagling", "username": "Lachlan_E", "age": 28}, {"firstName": "Jon", "surname": "Snow", "username": "Watcher21", "age": 20}]`) | |
if err := json.Unmarshal(userJson, &users); err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(users) | |
} |
View unmarshal_user.go
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
type User struct { | |
FirstName string `json:"firstName"` | |
LastName string `json:"surname"` |
View user_instantiation.go
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
func main() { | |
user := User{ | |
firstName: "Lachlan", | |
lastName: "Eagling", | |
username: "LachlanEagling", | |
age: 7, | |
} | |
if err := user.UpdateUsername("Lachlan_E"); err != nil { | |
fmt.Println(err) | |
} |
NewerOlder