Skip to content

Instantly share code, notes, and snippets.

View Deleplace's full-sized avatar

Valentin Deleplace Deleplace

View GitHub Profile
@Deleplace
Deleplace / set_implementations.go
Last active September 9, 2022 16:41
Comparison of memory footprint of map[int]bool vs. map[int]struct{}
package main
import (
"fmt"
"math/rand"
"runtime"
)
func main() {
BoolImplMemoryFootprint()
@Deleplace
Deleplace / insert_test.go
Created September 8, 2022 12:51
Benchmark heavy use of slices.Insert vs. heavy use of a dynamic-array-like insert func
package insert
import (
"fmt"
"testing"
"golang.org/x/exp/slices"
)
func BenchmarkGrow(b *testing.B) {
@Deleplace
Deleplace / insert_test.go
Created September 8, 2022 12:36
Benchmark heavy use of append vs. heavy use of slices.Insert
package insert
import (
"fmt"
"testing"
"golang.org/x/exp/slices"
)
func BenchmarkGrow(b *testing.B) {
@Deleplace
Deleplace / removeFirstByValue_test.go
Created August 31, 2022 09:22
Benchmark for a generic func: simple loop vs. calling slices.Index
package bench
import (
"testing"
"golang.org/x/exp/slices"
)
func BenchmarkRemoveFirstByValue(b *testing.B) {
items := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
@Deleplace
Deleplace / delete_test.go
Last active August 26, 2022 20:10
Benchmark deleting the parts of a slice, for various slice lengths
package delete
import (
"fmt"
"testing"
"golang.org/x/exp/slices"
)
func BenchmarkDeleteLast(b *testing.B) {
@Deleplace
Deleplace / main.dart
Created August 26, 2022 14:33
Iterate over list indexes and values
main() {
final items = ['a', 'b'];
items.asMap().forEach((i, x) {
print('index=$i, value=$x');
});
}
@Deleplace
Deleplace / main.dart
Created August 26, 2022 14:26
Iterate over list indexes and values
import 'package:collection/collection.dart';
main() {
final items = ['a', 'b'];
items.forEachIndexed((i, x) {
print('index=$i, value=$x');
});
}
@Deleplace
Deleplace / main.dart
Created August 26, 2022 14:25
Iterate over list indexes and values
import 'package:collection/collection.dart';
main() {
final items = ['a', 'b'];
items.forEachIndexed((i, value) {
print('index=$i, value=$value');
});
}
@Deleplace
Deleplace / delete_test.go
Created August 25, 2022 09:16
Benchmark: delete from slice vs. delete from slice and zero the discarded right tail
package slices
import "testing"
func delete[S ~[]E, E any](s S, i, j int) S {
_ = s[i:j] // bound check
return append(s[:i], s[j:]...)
}
@Deleplace
Deleplace / main.dart
Created July 4, 2022 08:53
vagrant-neutron-2212
void main() {
var i = 123;
var s = "$i";
print("String s has value: [" + s + "]");
}