swift 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,13 +23,6 @@ dbic++ can be found here http://github.com/deepfryed/dbicpp
23
23
  * EventMachine asynchronous interface.
24
24
  * Migrations.
25
25
 
26
- == Performance
27
-
28
- Swift prefers performance when it doesn't compromise the Ruby-ish interface. It's unfair to compare Swift to DataMapper
29
- and ActiveRecord which suffer under the weight of support for many more databases and legacy/alternative Ruby
30
- implementations. That said obviously if Swift were slower it would be redundant so benchmark code does exist in
31
- http://github.com/shanna/swift/tree/master/benchmarks
32
-
33
26
  == Synopsis
34
27
 
35
28
  === DB
@@ -193,7 +186,14 @@ You are not just limited to files - you can stream data from anywhere into MySQL
193
186
  PostgreSQL directly without creating temporary files.
194
187
 
195
188
 
196
- == Benchmarks
189
+ == Performance
190
+
191
+ Swift prefers performance when it doesn't compromise the Ruby-ish interface. It's unfair to compare Swift to DataMapper
192
+ and ActiveRecord which suffer under the weight of support for many more databases and legacy/alternative Ruby
193
+ implementations. That said obviously if Swift were slower it would be redundant so benchmark code does exist in
194
+ http://github.com/shanna/swift/tree/master/benchmarks
195
+
196
+ === Benchmarks
197
197
 
198
198
  The following bechmarks were run on a machine with 4G ram, 5200rpm sata drive,
199
199
  Intel Core2Duo P8700 2.53GHz and stock PostgreSQL 8.4.1.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/ext/extconf.rb CHANGED
@@ -4,7 +4,7 @@ require 'mkmf'
4
4
  Config::CONFIG['CC'] = 'g++'
5
5
  Config::CONFIG['CPP'] = 'g++'
6
6
 
7
- $CFLAGS = '-fPIC -O3'
7
+ $CFLAGS = '-fPIC -Os'
8
8
 
9
9
  def apt_install_hint pkg
10
10
  "sudo apt-get install #{pkg}"
data/ext/swift.cc CHANGED
@@ -27,7 +27,7 @@ static VALUE fRead;
27
27
  static VALUE fWrite;
28
28
 
29
29
  size_t tzoffset;
30
- char errstr[8192];
30
+ char errstr[8192];
31
31
 
32
32
  #define CSTRING(v) RSTRING_PTR(TYPE(v) == T_STRING ? v : rb_funcall(v, fStringify, 0))
33
33
  #define OBJ2STRING(v) (TYPE(v) == T_STRING ? v : rb_funcall(v, fStringify, 0))
@@ -420,8 +420,8 @@ VALUE rb_field_typecast(VALUE adapter, int type, const char *data, ulong len) {
420
420
  time_t epoch, offset;
421
421
  struct tm tm;
422
422
 
423
- char datetime[512], tzsign = ' ';
424
- int hour = 0, min = 0, sec = 0, tzhour = 0, tzmin = 0;
423
+ char tzsign = ' ';
424
+ int tzhour = 0, tzmin = 0;
425
425
  double usec = 0;
426
426
 
427
427
  switch(type) {
@@ -436,18 +436,25 @@ VALUE rb_field_typecast(VALUE adapter, int type, const char *data, ulong len) {
436
436
  case DBI_TYPE_TEXT:
437
437
  return rb_enc_str_new(data, len, rb_utf8_encoding());
438
438
  case DBI_TYPE_TIME:
439
- // if timestamp field has usec resolution, parse it.
440
- if (strlen(data) > 19 && data[19] == '.') {
441
- sscanf(data, "%s %d:%d:%d%lf%c%02d:%02d",
442
- datetime, &hour, &min, &sec, &usec, &tzsign, &tzhour, &tzmin);
439
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440
+ NOTE Flexibility sacrificed for performance.
441
+ Timestamp parser is very unforgiving and only parses
442
+ YYYY-MM-DD HH:MM:SS.ms[+-]HH:MM
443
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
444
+ memset(&tm, 0, sizeof(struct tm));
445
+ if (strchr(data, '.')) {
446
+ sscanf(data, "%04d-%02d-%02d %02d:%02d:%02d%lf%c%02d:%02d",
447
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec,
448
+ &usec, &tzsign, &tzhour, &tzmin);
443
449
  }
444
450
  else {
445
- sscanf(data, "%s %d:%d:%d%c%02d:%02d",
446
- datetime, &hour, &min, &sec, &tzsign, &tzhour, &tzmin);
451
+ sscanf(data, "%04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d",
452
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec,
453
+ &tzsign, &tzhour, &tzmin);
447
454
  }
448
- sprintf(datetime, "%s %02d:%02d:%02d", datetime, hour, min, sec);
449
- memset(&tm, 0, sizeof(struct tm));
450
- if (strptime(datetime, "%F %T", &tm)) {
455
+ tm.tm_year -= 1900;
456
+ tm.tm_mon -= 1;
457
+ if (tm.tm_mday > 0) {
451
458
  offset = tzoffset;
452
459
  epoch = mktime(&tm);
453
460
  if (tzsign == '+' || tzsign == '-') {
data/swift.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{swift}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shane Hanna", "Bharanee 'Barney' Rathna"]
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  "test/test_encoding.rb",
41
41
  "test/test_identity_map.rb",
42
42
  "test/test_io.rb",
43
+ "test/test_pool.rb",
43
44
  "test/test_timestamps.rb"
44
45
  ]
45
46
  s.homepage = %q{http://github.com/shanna/swift}
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
54
55
  "test/test_timestamps.rb",
55
56
  "test/helper.rb",
56
57
  "test/test_identity_map.rb",
58
+ "test/test_pool.rb",
57
59
  "examples/async.rb",
58
60
  "examples/scheme.rb",
59
61
  "examples/db.rb"
data/test/helper.rb CHANGED
@@ -4,6 +4,7 @@ require 'minitest/spec'
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  require 'swift'
7
+ require 'swift/pool'
7
8
 
8
9
  class MiniTest::Unit::TestCase
9
10
  end
data/test/test_pool.rb ADDED
@@ -0,0 +1,34 @@
1
+ require_relative 'helper'
2
+
3
+ describe 'Adapter' do
4
+ supported_by Swift::DB::Postgres, Swift::DB::Mysql do
5
+ describe 'Asynchronous connection pool' do
6
+ before do
7
+ Swift.db do |db|
8
+ type = db.is_a?(Swift::DB::Postgres) ? 'bytea' : 'blob'
9
+ db.execute %q{drop table if exists users}
10
+ db.execute %Q{create table users(id serial, name text)}
11
+ end
12
+ end
13
+
14
+ it 'creates connection pool' do
15
+ driver = Swift.db.kind_of?(Swift::DB::Mysql) ? 'mysql' : 'postgresql'
16
+ assert Swift::Pool.new 5, db: 'swift_test', driver: driver
17
+ end
18
+
19
+ describe 'Running queries' do
20
+ it 'should select data' do
21
+ rows = []
22
+ assert Swift.db.write('users', %w{name}, StringIO.new("user1\nuser2\nuser3\n"))
23
+ Swift.pool 5 do |pool|
24
+ pool.execute('select * from users') do |rs|
25
+ rows += rs.to_a
26
+ pool.execute('select * from users') {|rs| rows += rs.to_a }
27
+ end
28
+ end
29
+ assert_equal 6, rows.length
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 2
9
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shane Hanna
@@ -66,6 +66,7 @@ files:
66
66
  - test/test_encoding.rb
67
67
  - test/test_identity_map.rb
68
68
  - test/test_io.rb
69
+ - test/test_pool.rb
69
70
  - test/test_timestamps.rb
70
71
  has_rdoc: true
71
72
  homepage: http://github.com/shanna/swift
@@ -104,6 +105,7 @@ test_files:
104
105
  - test/test_timestamps.rb
105
106
  - test/helper.rb
106
107
  - test/test_identity_map.rb
108
+ - test/test_pool.rb
107
109
  - examples/async.rb
108
110
  - examples/scheme.rb
109
111
  - examples/db.rb