Skip to content

Instantly share code, notes, and snippets.

View gfx's full-sized avatar

FUJI Goro gfx

View GitHub Profile
#ifdef TX_DIRECT_THREADED_CODE
#define LABEL(x) CAT2(TX_DTC_, x)
#define LABEL_PTR(x) &&LABEL(x)
static void const* const*
tx_runops(pTHX_ tx_state_t* const st) {
static const void* const ops_address_table[] = {
LABEL_PTR(noop),
LABEL_PTR(move_to_sb),
LABEL_PTR(move_from_sb),
LABEL_PTR(save_to_lvar),
# http://github.com/gfx/p5-Benchmark-Memory
$ perl -Ilib example/template.pl
Perl/5.10.1 i686-linux
Text::Xslate/0.1041
Text::MicroTemplate/0.13
Text::MicroTemplate::Extended/0.11
Template/2.22
# 'tiny'は小さなテンプレート
Memory Usage for 'tiny' (1): # コンパイルあり
#!perl -w
use strict;
use Text::Xslate;
my $tx = Text::Xslate->new(
syntax => 'TTerse',
tag_start => '<%',
tag_end => '%>',
);
print $tx->render_string('Hello, <% lang %> world!', { lang => "TTerse" }), "\n";
diff --git a/lib/Template/Benchmark/Engines/TextMicroTemplate.pm b/lib/Template/Benchmark/Engines/TextMicroTemplate.pm
index 756421c..a4b1051 100644
--- a/lib/Template/Benchmark/Engines/TextMicroTemplate.pm
+++ b/lib/Template/Benchmark/Engines/TextMicroTemplate.pm
@@ -150,7 +150,7 @@ sub benchmark_functions_for_memory_cache
my $t = Text::MicroTemplate::File->new(
include_path => [ $template_dir ],
escape_func => undef,
- use_cache => 1,
+ use_cache => 2,
#!perl
use strict;
use Text::Xslate;
my %vpath = (
wrap_begin => '[% WRAPPER "base" %]',
wrap_end => '[% END %]',
base => 'Hello, [% content %] world!' . "\n",
content => 'Xslate',
#!perl -w
use strict;
use IPC::Open3;
use Symbol qw(gensym);
my($r, $w, $e) = (gensym, gensym, gensym);
my $pid = open3($r, $w, $e, "perl", "-e",
'print $_ qq{x} x (1024 * 1024) for \*STDOUT, \*STDERR');
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw(encode_utf8);
use FindBin qw($Bin);
use Text::Markdown qw(markdown);
use Text::Xslate qw(mark_raw);
Perlの乱数についてIRCで盛り上がったのでまとめておく。
結論からいうと、srand()はPerl5組み込みのものでよい。乱数の生成はMath::Random::MTがよいとおもう。
Perlのrand()の実装はConfigure時に選べるようだが((perl -V:randfunc でかくにんできる))、ふつうはdrand48()がつかわれる。これは下位ビットがまったくランダムでないことで知られるrand(3)よりはましだが、しょせん線形合同法なのでセッションIDなどを作るのには安全ではない。安全な乱数を作るためにtime()やSHA1を混ぜ込んだりするほうほうもよくつかわれるが、そのくらいならはじめからM::R::MTを使ったほうがいいとおもう。
なお、srand()はあれば/dev/urandomを読むので、自前でsrand(time)などとするのはよくない。また、最初にrand()を呼ぶときに自動的に呼ばれるので、ふつうは明示的によぶひつようすらない。ただし、どこかでrand()してからfork(2)をすると、サブプロセスで乱数系列がすべておなじになってしまうので注意がひつようである。
id:kazuho++ id:sfujiwara++
参考文献:
- http://wellington.pm.org/archive/200704/randomness/index.html#slide0
@gfx
gfx / xshelper.h
Created September 11, 2010 08:01
/*
=head1 NAME
xshelper.h - Helper C header file for XS modules
=head1 DESCRIPTION
// This includes all the perl header files and ppport.h
#include "xshelper.h"