Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
static bool is_prime(const int candidate) {
if( candidate <= 1 )
return false;
if( candidate <= 3 )
@schwern
schwern / mxms_vs_ms.pl
Created September 24, 2015 08:28
Bencharmking MooseX::Method::Signatures vs Method::Signatures vs plain Perl
{
package Plain;
use Moose;
sub no_args { return 42 }
sub one_arg {
my $self = shift;
my $arg = shift;
@schwern
schwern / gist:b4cc353399abae1c7f5a
Last active August 29, 2015 14:15
Overhead of a wrapper function in Perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
sub match { $_[0] =~ $_[1] }
sub wrapper { match(@_) }
sub wrapper_alias_args { &match }
my @args = ("foo", qr/bar/);
@schwern
schwern / git-unpushed-ref
Last active August 29, 2015 14:15
Find the nth unpushed reference in the current branch.
#!/usr/bin/env perl
use strict;
use warnings;
sub current_branch {
my $branch=`git symbolic-ref --short HEAD`;
chomp $branch;
die "Cannot figure out the current branch.\n" unless $branch;
$ git remote show origin
* remote origin
Fetch URL: git://github.com/CPAN-API/cpan-api.git
Push URL: git://github.com/CPAN-API/cpan-api.git
HEAD branch: master
Remote branches:
apeiron/signature-false-positive-pod tracked
apeiron/support-signed-dists tracked
grantm/#159 tracked
haarg/download-ssl tracked
$ perl -wle 'use Devel::Peek; $foo = 1.23; print $foo; print int $foo; Dump $foo'
1.23
1
SV = PVNV(0x7f99f3804730) at 0x7f99f4808350
REFCNT = 1
FLAGS = (NOK,POK,pIOK,pNOK,pPOK)
IV = 1
NV = 1.23
PV = 0x7f99f3609040 "1.23"\0
CUR = 4
use strict; use warnings; use 5.010;
use DBI;
use Benchmark qw{:all} ;
my $EXECUTES_PER_PREPARE = 10;
my $BENCH_TIMES = int(200_000 / $EXECUTES_PER_PREPARE);
my $dbh = DBI->connect('DBI:mysql:database=test', '', '',
{RaiseError => 1, AutoCommit => 0}
);
@schwern
schwern / gist:f6dab96308a0322d2b22
Created December 28, 2014 05:28
% of Steam users with laptops
#! /usr/bin/perl
use v5.18;
use strict;
use warnings;
my $total = 0;
local $/ = "\n\n";
while(<DATA>) {
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
my $String = "ATGC" x 1000;
my @Genes = qw(A T G C);
my %Count;
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
my $String = "ATGC" x 1000;
my @Genes = qw(A T G C);
my %Count;