Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env ruby
# encoding: utf-8
#
# Script to export the scripts inside the Scripts.rvdata2 data file to Data/exported_scripts as plain text Ruby files.
# If you run this script from inside RPG Maker VX Ace, I would suggest creating the Data/exported_scripts folder yourself
# as RGSS3 doesn't seem to support requiring FileUtils.
# Based on HIRATA Yasuyuki / 平田 泰行's rvdata2_dump.rb script: https://gist.github.com/hirataya/1853033
begin
require 'fileutils'
rescue LoadError

To test out the cache miss behavior of read operations, run a program building the index (30k entries) then another program building then reading the index (30k queries), and find their diff.

Here's how to generate the test script cmd.sh

3.times do |i|
  %w[triez hash da].each do |ty|
    puts "valgrind --tool=cachegrind --cachegrind-out-file=tmp/#{ty} ruby t.rb #{ty}"
    puts "valgrind --tool=cachegrind --cachegrind-out-file=tmp/#{ty}.read ruby t.rb #{ty} read"
    puts "cg_diff tmp/#{ty} tmp/#{ty}.read > tmp/#{ty}#{i}.diff"
Visual Studio 2012 Performance Profiler Result
Noise Reduction is enabled. Displaying HOT PATHs only.
Level Function Name Number of Calls Elapsed Inclusive Time % Elapsed Exclusive Time %
0 mruby.exe 0 100 0
1 mainCRTStartup 1 100 0
2 __tmainCRTStartup 1 100 0.01
3 main 1 99.99 0
4 mrb_load_file_cxt 1 99.97 0
5 load_exec 1 99.97 29.52
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@skandhas
skandhas / mruby.cxx
Created December 27, 2012 13:51 — forked from mattn/mruby.cxx
#ifndef mruby_hpp
#define mruby_hpp
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/array.h"
#include "mruby/string.h"
#include "mruby/compile.h"
#include "mruby/dump.h"
#include "mruby/variable.h"
#include <string>
@skandhas
skandhas / ruby_china_nodes_info.rb
Created May 21, 2012 04:27
Fetch Ruby China nodes infomation.
#encoding:utf-8
require "watir-webdriver"
def ruby_china_nodes_info
@browser = Watir::Browser.new
(1..49).inject([]) { |total,i| total << fetch_node_info(i)}
.sort_by{|_,topics| -topics }
.slice(0...30)
.tap { @browser.close }
end
@skandhas
skandhas / ns
Created May 8, 2012 12:12 — forked from hooopo/ns
ns
有人用过cell么?
<span style="font-size: small;"><a target="_blank" href="http://rubyforge.org/frs/?group_id=2978&amp;release_id=9650">http://rubyforge.org/frs/?group_id=2978&amp;release_id=9650</a>
<br /></span>
<br /><span style="font-size: small;"> </span>
<br /><span style="font-size: small;">
<br />非常小,源代码一目了然。感觉虽然有点土,但比自己做个module的方式好一点点
<br />号称: 代替发挥component作用的controller, 这样就不需要邪恶的render_component了
<br /></span>
<br /><span style="font-size: small;">A cell acts as a lightweight controller in the sense that it will assign variables and render a view.</span>
class Sumify
def self.run(num, collection)
collection.size.times.map { |n| collection.combination(n).to_a }.flatten(1).select { |c| c.inject(:+) == num }
end
end
@skandhas
skandhas / rake-for-cpp
Last active August 29, 2015 14:07 — forked from locatw/rake-for-cpp
# coding: utf-8
require 'fileutils'
### 定数 ###
COMPILER = "g++"
CPPFLAGS = %w{}
LDFLAGS = %w{}
INC_DIRS = []
LIB_DIRS = []
TARGET = "app"
@skandhas
skandhas / dh.c
Created February 6, 2014 06:34 — forked from cloudwu/dh.c
// The 202020202th prime
#define P 4267031897ul
#define G 5
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
static inline uint32_t