liquid-c 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2431d1b61b78e144d34a423a60c5463fb8c21a87
4
- data.tar.gz: 7cf1e00087a7c80cb6b19d099756149d3d136155
3
+ metadata.gz: 1f1e4b7a91ef500fc48563ecdff875658c045b0e
4
+ data.tar.gz: 460cbca81b9ff70a9c20e4051cdc62a26a1e2c7b
5
5
  SHA512:
6
- metadata.gz: 29ebcbdcc043203d454b979ae8b136263b14d8dd885ea0556d699c7aa006375798eb408c8db048258869b91bd1cf6e519f37a1fc6609f590c078bbea15893c9d
7
- data.tar.gz: 3b2628f520d13b1b487da6d473c9357b631cb860bdf74de3d288d3345584a954b2eaa71ef221d8aac4e21b5474be3d3570c709e7e846afdcbeeb8031ea7ad24d
6
+ metadata.gz: 1ecf742609e18e26a982897562f3ff0ef0c06e77045d12b98ad36fda3081e4350faffb9bae860ce1ecc060d8c6138b7fd482c323d763538dc38b13bc5738d1f8
7
+ data.tar.gz: 817638febdcb9a54399ab8aec528091b1c24f66510816e455f09b85bce9b2c1f7a5e559a89ab5611327b1d0f780c9d62fcb36ad0b231eaba35554f551bcdc80e
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ tmp
6
6
  *.o
7
7
  *.bundle
8
8
  ext/*/Makefile
9
+ *.so
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.0
6
5
  gemfile:
data/Gemfile CHANGED
@@ -3,3 +3,11 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'liquid', github: 'Shopify/liquid', branch: 'master'
6
+
7
+ group :test do
8
+ gem 'spy', '0.4.1'
9
+ end
10
+
11
+ group :development do
12
+ gem 'byebug'
13
+ end
data/README.md CHANGED
@@ -27,6 +27,25 @@ then just use the documented API for the liquid Gem.
27
27
  of an array of strings, which only implements the shift method
28
28
  to get the next token.
29
29
 
30
+ ## Performance
31
+
32
+ To compare Liquid-C's performance with plain Liquid run
33
+
34
+ bundle exec rake compare:run
35
+
36
+ The latest benchmark results are shown below:
37
+
38
+ user system total real
39
+ Liquid: 0.000000 0.000000 246.950000 (247.499526)
40
+ Liquid-C: 0.000000 0.010000 224.270000 (224.794395)
41
+ Ratio: 90.82619215891624%
42
+
43
+ ## Developing
44
+
45
+ bundle install
46
+ # run tests
47
+ bundle exec rake
48
+
30
49
  ## Contributing
31
50
 
32
51
  1. Fork it ( http://github.com/Shopify/liquid-c/fork )
data/Rakefile CHANGED
@@ -2,7 +2,9 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/extensiontask'
5
+ require 'benchmark'
5
6
 
7
+ ENV['DEBUG'] = 'true'
6
8
  Rake::ExtensionTask.new("liquid_c")
7
9
 
8
10
  task :default => :test
@@ -34,12 +36,12 @@ end
34
36
  namespace :benchmark do
35
37
  desc "Run the liquid benchmark with lax parsing"
36
38
  task :run do
37
- ruby "./performance.rb benchmark lax"
39
+ ruby "./performance.rb c benchmark lax"
38
40
  end
39
41
 
40
42
  desc "Run the liquid benchmark with strict parsing"
41
43
  task :strict do
42
- ruby "./performance.rb benchmark strict"
44
+ ruby "./performance.rb c benchmark strict"
43
45
  end
44
46
  end
45
47
 
@@ -47,11 +49,28 @@ end
47
49
  namespace :profile do
48
50
  desc "Run the liquid profile/performance coverage"
49
51
  task :run do
50
- ruby "./performance.rb profile lax"
52
+ ruby "./performance.rb c profile lax"
51
53
  end
52
54
 
53
55
  desc "Run the liquid profile/performance coverage with strict parsing"
54
56
  task :strict do
55
- ruby "./performance.rb profile strict"
57
+ ruby "./performance.rb c profile strict"
58
+ end
59
+ end
60
+
61
+ namespace :compare do
62
+ include Benchmark
63
+ desc "Compare Liquid to Liquid + Liquid-C"
64
+ task :run do
65
+ bare = Benchmark.measure do
66
+ ruby "./performance.rb bare profile lax"
67
+ end
68
+ liquid_c = Benchmark.measure do
69
+ ruby "./performance.rb c profile lax"
70
+ end
71
+ Benchmark.benchmark(CAPTION, 10, FORMAT, "Liquid:", "Liquid-C:") do |x|
72
+ [bare, liquid_c]
73
+ end
74
+ puts "Ratio: #{liquid_c.real / bare.real * 100}%"
56
75
  end
57
76
  end
@@ -1,4 +1,8 @@
1
1
  require 'mkmf'
2
2
  $CFLAGS << ' -Wall -Werror'
3
+ compiler = RbConfig::MAKEFILE_CONFIG['CC']
4
+ if ENV['DEBUG'] == 'true' && compiler =~ /gcc|g\+\+/
5
+ $CFLAGS << ' -fbounds-check'
6
+ end
3
7
  $warnflags.gsub!(/-Wdeclaration-after-statement/, "")
4
8
  create_makefile("liquid_c")
@@ -1,9 +1,12 @@
1
1
  #include "liquid.h"
2
+ #include "tokenizer.h"
2
3
 
3
4
  VALUE mLiquid;
5
+ rb_encoding *utf8_encoding;
4
6
 
5
7
  void Init_liquid_c(void)
6
8
  {
9
+ utf8_encoding = rb_utf8_encoding();
7
10
  mLiquid = rb_define_module("Liquid");
8
11
  init_liquid_tokenizer();
9
12
  }
@@ -1,11 +1,11 @@
1
- #ifndef LIQUID_H
1
+ #if !defined(LIQUID_H)
2
2
  #define LIQUID_H
3
3
 
4
4
  #include <ruby.h>
5
+ #include <ruby/encoding.h>
5
6
  #include <stdbool.h>
6
7
 
7
- #include "tokenizer.h"
8
-
9
8
  extern VALUE mLiquid;
9
+ extern rb_encoding *utf8_encoding;
10
10
 
11
11
  #endif
@@ -1,9 +1,10 @@
1
1
  #include "liquid.h"
2
+ #include "tokenizer.h"
2
3
 
3
4
  VALUE cLiquidTokenizer;
4
- rb_encoding *utf8_encoding;
5
5
 
6
- static void tokenizer_mark(void *ptr) {
6
+ static void tokenizer_mark(void *ptr)
7
+ {
7
8
  tokenizer_t *tokenizer = ptr;
8
9
  rb_gc_mark(tokenizer->source);
9
10
  }
@@ -21,8 +22,8 @@ static size_t tokenizer_memsize(const void *ptr)
21
22
 
22
23
  const rb_data_type_t tokenizer_data_type = {
23
24
  "liquid_tokenizer",
24
- {tokenizer_mark, tokenizer_free, tokenizer_memsize,},
25
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
25
+ { tokenizer_mark, tokenizer_free, tokenizer_memsize, },
26
+ #if defined(RUBY_TYPED_FREE_IMMEDIATELY)
26
27
  NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
27
28
  #endif
28
29
  };
@@ -134,5 +135,4 @@ void init_liquid_tokenizer()
134
135
  rb_define_alloc_func(cLiquidTokenizer, tokenizer_allocate);
135
136
  rb_define_method(cLiquidTokenizer, "initialize", tokenizer_initialize_method, 1);
136
137
  rb_define_method(cLiquidTokenizer, "shift", tokenizer_shift_method, 0);
137
- utf8_encoding = rb_utf8_encoding();
138
138
  }
@@ -1,9 +1,6 @@
1
- #ifndef LIQUID_TOKENIZER_H
1
+ #if !defined(LIQUID_TOKENIZER_H)
2
2
  #define LIQUID_TOKENIZER_H
3
3
 
4
- #include <ruby.h>
5
- #include <ruby/encoding.h>
6
-
7
4
  enum token_type {
8
5
  TOKEN_NONE,
9
6
  TOKEN_INVALID,
@@ -1,19 +1,18 @@
1
1
  require 'liquid/c/version'
2
2
  require 'liquid'
3
-
4
- # workaround bundler issue #2947 which could cause an old extension to be used
5
- require 'rbconfig'
6
- ext_path = File.expand_path("../../liquid_c.#{RbConfig::CONFIG['DLEXT']}", __FILE__)
7
- if File.exists?(ext_path)
8
- require ext_path
9
- else
10
- require 'liquid_c'
11
- end
3
+ require 'liquid_c'
12
4
 
13
5
  Liquid::Template.class_eval do
14
6
  private
15
7
 
8
+ alias_method :ruby_tokenize, :tokenize
9
+
16
10
  def tokenize(source)
17
- Liquid::Tokenizer.new(source.to_s)
11
+ if @line_numbers
12
+ ruby_tokenize(source)
13
+ else
14
+ Liquid::Tokenizer.new(source.to_s)
15
+ end
18
16
  end
19
17
  end
18
+
@@ -1,5 +1,5 @@
1
1
  module Liquid
2
2
  module C
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require 'liquid'
2
- require 'liquid/c'
2
+ require 'liquid/c' if ARGV.shift == "c"
3
3
  liquid_lib_dir = $LOAD_PATH.detect{ |p| File.exists?(File.join(p, 'liquid.rb')) }
4
4
 
5
5
  script = ARGV.shift or abort("unspecified performance script")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid-c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Thacker-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid