Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️
Researching

Rudi Theunissen rtheunissen

🕵️
Researching
View GitHub Profile
View gist:64a362307d90b9c8405350024ef11a2a
#pragma once
#pragma warning(push)
#pragma warning(disable:4996)
#include <cassert>
#include <memory>
#include <vector>
@rtheunissen
rtheunissen / decimal_refcount.php
Created Feb 19, 2019
Summary of refcount shortcuts for ext-decimal
View decimal_refcount.php
<?php
$a = "1";
$b = "2";
/**
* This should reuse the decimal created for A as the result.
*/
$c = \Decimal\Decimal::valueOf($a)->add($b);
debug_zval_dump($c);
// object(Decimal\Decimal)#1 (2) refcount(2){
@rtheunissen
rtheunissen / copy_on_write_lazy_map.php
Last active Feb 5, 2019
A concept for lazy collections using copy-on-write (I think)
View copy_on_write_lazy_map.php
<?php
interface Collection
{
/**
* @return static
*/
function map(callable cb): Collection;
// filter
// reduce
@rtheunissen
rtheunissen / benchmark.php
Created Oct 28, 2018
Benchmark between BC Math and Decimal
View benchmark.php
<?php
use Decimal\Decimal;
/* Number of times to perform each calculation. */
$iterations = 1000000;
/* Candidates */
define("DECIMAL", "decimal");
define("BC_MATH", "bcmath");
@rtheunissen
rtheunissen / gmpi_dec_bench.php
Created Sep 29, 2018
Basic benchmark for gmpi vs decimal, using bcmath as reference
View gmpi_dec_bench.php
<?php
ini_set('memory_limit', -1);
srand(0);
$length = 100000;
$maxInt = 10 ** 10;
$values = [];
for ($i = 0; $i < $length; $i++) {
$int = (rand() % $maxInt);
@rtheunissen
rtheunissen / php_bug63217_benchmark.php
Last active Jun 30, 2018
PHP Bug #63217 Benchmark Script
View php_bug63217_benchmark.php
<?php
// See https://github.com/php/php-src/pull/3351
$arr = [
"foo" => true,
"foobar" => 3,
"elePHPant" => "qux",
"long_key_name" => "something contrived",
"123" => 76,
View prefetched.py
def prefetched_related(instance, name, default=None):
"""
Attempts to find and return prefetched data on a model.
Usage:
values, prefetched = prefetched_related(instance, 'name')
values : A list of prefetched values for the field.
prefetched : True if the requested field was prefetched on the instance.
"""
You can’t perform that action at this time.