Skip to content

Instantly share code, notes, and snippets.

View AngelicosPhosphoros's full-sized avatar

AngelicosPhosphoros

View GitHub Profile
@AngelicosPhosphoros
AngelicosPhosphoros / combinations_benchmark.rs
Last active December 12, 2020 18:11
Comparison between using itertools crate, indexing and slice iterations
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use itertools::Itertools;
use std::convert::TryInto;
fn gen_numbers(size: u32) -> Vec<u32> {
use rand::prelude::Rng;
let mut rng = rand::thread_rng();
let dist = rand::distributions::Uniform::new_inclusive(1u32, 10_000);
let size: usize = size.try_into().unwrap();
(0..size).map(|_| rng.sample(dist)).collect()
@AngelicosPhosphoros
AngelicosPhosphoros / main.rs
Created November 18, 2021 01:22
Tuple uniqueness test
#![feature(const_type_id)]
use std::any::TypeId;
use std::mem::{size_of, align_of};
pub trait IsUniqueTuple{
const IS_UNIQUE: bool;
type ElementTypesArray;
const ELEMENT_TYPES_SORTED: Self::ElementTypesArray;
}
@AngelicosPhosphoros
AngelicosPhosphoros / bench.rs
Last active April 10, 2025 15:08
Benchmark of taking Rust Vec items by predicate
// Results:
// | algorithm | Mixed | Odds first | Evens first |
// |-------------|-------|------------|-------------|
// |sort-split | 465us | 35us | 10us |
// |drain_filter | 26us | 24us | 22.5us |
// |retain-uninit| 17us | 21us | 19us |
//
// See also explanation on StackOverflow: https://stackoverflow.com/a/73005333/8195987
#![feature(drain_filter)]
#![feature(no_core)]
#![no_core]
#![crate_type="rlib"]
#![feature(rustc_attrs)]
#![feature(fundamental)]
#![feature(lang_items)]
#![feature(intrinsics)]
#![feature(auto_traits)]
#![allow(non_camel_case_types)]
@AngelicosPhosphoros
AngelicosPhosphoros / StrCmpAvx.c
Created June 27, 2025 22:47
strcmp implementation with AVX (works due to paging of virtual memory)
#include <stddef.h>
#include <stdint.h>
#include <immintrin.h>
#include <xmmintrin.h>
static constexpr size_t cPageSize = 4096;
typedef __m256i u256;
typedef __m128i u128;