Skip to content

Instantly share code, notes, and snippets.

# Patch to ActiveResource (based on the 2.3.2 codebase) for including the class name in the JSON generated.
# This is so the receiving end (Rails) can more easily manage the params hash.
#
# The current implementation sends the attributes as top-level JSON keys, which ends up on the other end as:
# params[:some_attribute]
# params[:some_other_attribute]
# params[:something_else] # => not related to the posted JSON
#
# This makes it hard to do things like:
# obj = SomeModel.new(params[:some_model])
# Comparing JSON parsing (yajl-ruby) and file sizes against YAML (Syck),
# Marshal, and XML (Libxml and Nokogiri) using ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
# It should be noted that for this test Yajl, the JSON gem, YAML and Marshal all return Ruby objects (in this case, a Ruby Hash).
# But both the Libxml and Nokogiri tests merely ran a #load call, which returns their respective XMLDocument classes.
# In order to be *fully* accurate I had to convert said document to a hash (in pure ruby) which is
# painfully slow. But made the test more accurate.
== Raw
JSON(Yajl): contacts.json 2405005 bytes
0.110000 0.010000 0.120000 ( 0.123369)
# Override the default db:drop and db:create Rake tasks to fix bug with using a database driver
# other than mysql, postgres or sqlite.
namespace :db do
task :create do
@charset = ENV['CHARSET'] || 'utf8'
@collation = ENV['COLLATION'] || 'utf8_general_ci'
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
begin
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation))
# encoding: UTF-8
# This was ported from Yajl (http://github.com/lloyd/yajl)
# The reason for this is because Ruby 1.8's pack/unpack("U"), nor 1.9's native Unicode
# implementation seemed to support surrogate characters (I may be wrong about that...)
# The example below would throw exceptions on *every* attempt I'd tried to decode it.
# But Yajl decodes it fine, so I ported it's decoding logic into pure Ruby for us all
# to enjoy :)
#
#
# Starting benchmark parsing 2405005 bytes of JSON data 1 times
Yajl::FFI.parse (FFI)
13.530000 8.170000 21.700000 ( 21.802142)
Yajl::Parser.parse (C, from an IO)
0.180000 0.010000 0.190000 ( 0.200328)
Yajl::Parser.parse (C, from a String)
0.200000 0.020000 0.220000 ( 0.214135)
JSON.parse (C)
0.270000 0.020000 0.290000 ( 0.291869)
module EventMachine
module Protocols
module JsonProtocol
def post_init
@parser = Yajl::Parser.new
@parser.on_parse_complete = method(:receive_object)
@encoder = Yajl::Encoder.new
end
def receive_data(data)
>> Time.now.to_json
=> "\"2009-08-25T13:30:18-07:00\""
>> require 'yajl/json_gem'
>> Time.now.to_json
=> "Tue Aug 25 13:30:26 -0700 2009"
gcc -Ivm/external_libs/libtommath -Ivm/external_libs/libgdtoa -Ivm/external_libs/onig -Ivm/external_libs/libffi/include -Ivm/external_libs/libbstring -Ivm/external_libs/libcchash -Ivm/external_libs/libmquark -Ivm/external_libs/libmpa -Ivm/external_libs/libltdl -Ivm/external_libs/libev -Ivm/test/cxxtest -Ivm -I. -Ivm/assembler -Ivm/assembler/udis86-1.7 -pipe -Wall -Wno-deprecated -DBASE_PATH=\"/Users/brianmario/Downloads/rubinius\" -DRBA_PATH=\"/Users/brianmario/Downloads/rubinius/runtime\" -mdynamic-no-pic -DENABLE_LLVM -DHAS_EXECINFO -ggdb3 -O2 -Werror -DRBX_PROFILER -Ivm/external_libs/llvm/include -c -o vm/environment.o vm/environment.cpp 2>&1
In file included from vm/external_libs/llvm/include/llvm/Support/PointerLikeTypeTraits.h:18,
from vm/external_libs/llvm/include/llvm/ADT/PointerIntPair.h:17,
from vm/external_libs/llvm/include/llvm/Use.h:30,
from vm/external_libs/llvm/include/llvm/Value.h:18,
from vm/external_libs/llvm/include/llvm/Us
$ ./configure --enable-llvm
Using LLVM: auto
Checking for existing LLVM tree: not found.
Fetching http://asset.rubini.us/prebuilt/llvm-x86_64-apple-darwin10.0.0.tar.bz2...
######################################################################## 100.0%
Prebuilt packages updated.
Unpacking prebuilt LLVM for x86_64-apple-darwin10.0.0: done!
Checking for function 'backtrace': found!
rake
(in /Users/brianmario/Downloads/rubinius.git)
LLVM inclusion enabled.
GEN vm/gen/inst_list.hpp
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby vm/codegen/instruction_macros.rb
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby vm/instructions.rb
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby vm/codegen/field_extract.rb vm/builtin/object.hpp vm/builtin/integer.hpp vm/builtin/executable.hpp vm/builtin/access_variable.hpp vm/builtin/fixnum.hpp vm/builtin/array.hpp vm/builtin/bignum.hpp vm/builtin/block_environment.hpp vm/builtin/bytearray.hpp vm/builtin/io.hpp vm/builtin/channel.hpp vm/builtin/module.hpp vm/builtin/class.hpp vm/builtin/compiledmethod.hpp vm/builtin/data.hpp vm/builtin/dir.hpp vm/builtin/exception.hpp vm/builtin/float.hpp vm/builtin/immediates.hpp vm/builtin/iseq.hpp vm/builtin/list.hpp vm/builtin/lookuptable.hpp vm/builtin/memorypointer.hpp vm/builtin/methodtable.hpp vm/builtin/nativefunction.hpp vm/builtin/regexp.hpp vm/builtin/sele