ease_engine 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +4 -0
  5. data/README.md +33 -0
  6. data/Rakefile +1 -0
  7. data/benchmark/echo/echo_client.rb +90 -0
  8. data/benchmark/echo/echo_packet.rb +9 -0
  9. data/benchmark/echo/echo_server.rb +48 -0
  10. data/benchmark/fps.rb +23 -0
  11. data/benchmark/http.rb +9 -0
  12. data/benchmark/loop/Makefile +39 -0
  13. data/benchmark/loop/Makefile.rb +11 -0
  14. data/benchmark/loop/Rakefile +42 -0
  15. data/benchmark/loop/loop.c +38 -0
  16. data/benchmark/loop/loop.cs +33 -0
  17. data/benchmark/loop/loop.go +33 -0
  18. data/benchmark/loop/loop.js +23 -0
  19. data/benchmark/loop/loop.php +22 -0
  20. data/benchmark/loop/loop.rb +19 -0
  21. data/benchmark/loop/loop.scala +30 -0
  22. data/benchmark/loop/loop_c +0 -0
  23. data/benchmark/loop/loop_cs +0 -0
  24. data/benchmark/loop/loop_go +0 -0
  25. data/benchmark/measure/measure_client.rb +76 -0
  26. data/benchmark/measure/measure_server.rb +47 -0
  27. data/benchmark/process.rb +3 -0
  28. data/benchmark/tcp/tcp_client.rb +45 -0
  29. data/benchmark/tcp/tcp_server.rb +40 -0
  30. data/benchmark/udp/udp_client.rb +84 -0
  31. data/benchmark/udp/udp_packet.rb +40 -0
  32. data/benchmark/udp/udp_server.rb +33 -0
  33. data/bin/console +14 -0
  34. data/bin/setup +7 -0
  35. data/ease_engine.gemspec +27 -0
  36. data/lib/ease_engine.rb +35 -0
  37. data/lib/ease_engine/application.rb +269 -0
  38. data/lib/ease_engine/buffer.rb +25 -0
  39. data/lib/ease_engine/data.rb +158 -0
  40. data/lib/ease_engine/frame.rb +38 -0
  41. data/lib/ease_engine/http.rb +42 -0
  42. data/lib/ease_engine/log.rb +109 -0
  43. data/lib/ease_engine/measure.rb +25 -0
  44. data/lib/ease_engine/packet.rb +150 -0
  45. data/lib/ease_engine/platform.rb +19 -0
  46. data/lib/ease_engine/process.rb +31 -0
  47. data/lib/ease_engine/socket.rb +174 -0
  48. data/lib/ease_engine/time.rb +22 -0
  49. data/lib/ease_engine/timer.rb +72 -0
  50. data/lib/ease_engine/version.rb +3 -0
  51. data/lib/ease_engine/watcher.rb +95 -0
  52. data/types/Rakefile +83 -0
  53. data/types/csharp/EaseEngine.cs +39 -0
  54. data/types/csharp/EaseEngine/Buffer.cs +49 -0
  55. data/types/csharp/EaseEngine/Measure.cs +47 -0
  56. data/types/csharp/EaseEngine/Time.cs +41 -0
  57. data/types/csharp/EaseEngine/Version.cs +7 -0
  58. data/types/csharp/Unity/Assets/Menu.cs +56 -0
  59. data/types/csharp/Unity/Assets/Menu.unity +0 -0
  60. metadata +158 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f43c77e968948ba8cfaf51290acdce0be838f49a
4
+ data.tar.gz: 179eaeba3961541f2aae7e60ac0f0aa38f4ebca6
5
+ SHA512:
6
+ metadata.gz: ff6ac2038a1e486e41914acfb0e7f187189908cbaadcfff7b0a33b61a6653de27bbfe7ea4a84430f16f44309806bfdfe0caa4340840457f2ad8345621ce4f96a
7
+ data.tar.gz: a941ca8a98d4530e1c34838e6f0f90f67d41700034e60f8d2a275043fc34c030a56b46f6e37636c9bf32828708bb3a13f690d2bc471129cb567ee444e6c2c95e
@@ -0,0 +1,25 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /benchmark/loop/loop
11
+ /benchmark/loop/*.o
12
+ /benchmark/loop/obj
13
+ /benchmark/loop/*.exe
14
+ /benchmark/loop/*.class
15
+ /benchmark/loop/node_modules
16
+ *.log
17
+ *.pid
18
+ *.dll
19
+ *.meta
20
+ /types/csharp/Unity/*.csproj
21
+ /types/csharp/Unity/*.sln
22
+ /types/csharp/Unity/*.userprefs
23
+ /types/csharp/Unity/Library
24
+ /types/csharp/Unity/ProjectSettings
25
+ /types/csharp/Unity/Temp
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ease_engine.gemspec
4
+ gemspec
@@ -0,0 +1,33 @@
1
+ # EaseEngine
2
+
3
+ Easy application programming scripts.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ease_engine'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ease_engine
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/ease_engine/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,90 @@
1
+ require "ease_engine"
2
+ require "./echo_packet"
3
+
4
+ class BenchmarkApplication < EaseEngine::Application
5
+ def on_start
6
+ super
7
+
8
+ EaseEngine::Frame.fps = 60
9
+
10
+ host = ARGV[ 0 ]
11
+ port = ARGV[ 1 ].to_i
12
+ @tcp_num = ARGV[ 2 ].to_i
13
+ @udp_num = ARGV[ 3 ].to_i
14
+
15
+ @tcp_packet = EchoPacket.new
16
+ @tcp_packet.str = "0123456789ABCDEF" * 32 # 512
17
+ # @tcp_packet.str = "0123456789ABCDEF" * 128 # 2048
18
+ # @tcp_packet.str = "0123456789ABCDEF" * 4096 # 64KB
19
+
20
+ @udp_packet = EchoPacket.new
21
+ @udp_packet.str = "0123456789ABCDEF" * 32 # 512
22
+
23
+ @tcp_len = @tcp_packet.str.length
24
+ @udp_len = @udp_packet.str.length
25
+ EE_LOG_DBG.call "tcp_len=#{@tcp_len} udp_len=#{@udp_len}"
26
+
27
+ @tcp_num.times{|i|
28
+ tcp_socket = EaseEngine::TCPSocket.new( host, port )
29
+ # EE_LOG_DBG.call "tcp_num=#{i + 1}"
30
+ add_connect_socket( tcp_socket )
31
+ }
32
+
33
+ @udp_num.times{|i|
34
+ udp_socket = EaseEngine::UDPSocket.new
35
+ # EE_LOG_DBG.call "udp_num=#{i + 1}"
36
+ add_socket( udp_socket )
37
+ write_packet( udp_socket, @udp_packet, 0, host, port )
38
+ }
39
+
40
+ @measure.check
41
+ EE_LOG_DBG.call "host=#{host} port=#{port} tcp_num=#{@tcp_num} udp_num=#{@udp_num} watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec}"
42
+ @measure.start
43
+
44
+ @is_update = ( 0 < @watcher.size )
45
+
46
+ @measure_read_socket = EaseEngine::Measure.new
47
+ end
48
+
49
+ def on_update
50
+ if 1000000 <= @measure.check
51
+ EE_LOG_DBG.call "tcp_num=#{@tcp_num} udp_num=#{@udp_num} watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec} count=#{@measure.count}"
52
+
53
+ @measure.start
54
+ @is_update = ( 0 < @watcher.size )
55
+ end
56
+ end
57
+
58
+ def on_end
59
+ super
60
+
61
+ @measure_read_socket.check
62
+ EE_LOG_DBG.call "update_usec=#{@measure_read_socket.update_usec}"
63
+ end
64
+
65
+ def on_connected_socket( socket )
66
+ write_packet( socket, @tcp_packet, 0 )
67
+ end
68
+
69
+ def on_read_socket( socket, packet )
70
+ send( "on_#{packet.packet_name.gsub( /\./, '_' )}", socket, packet )
71
+ end
72
+
73
+ def on_EchoPacket( socket, packet )
74
+ if socket.kind_of?( EaseEngine::TCPSocket )
75
+ @tcp_num -= 1
76
+ else
77
+ @udp_num -= 1
78
+ end
79
+
80
+ len = packet.str.length
81
+ if @tcp_len != len && @udp_len != len
82
+ EE_LOG_ERR.call "Packet Error len=#{len}"
83
+ @is_update = false
84
+ end
85
+ remove_socket( socket )
86
+
87
+ @is_update = false if 0 == @watcher.size
88
+ end
89
+ end
90
+ BenchmarkApplication::run
@@ -0,0 +1,9 @@
1
+ require "ease_engine"
2
+
3
+ class EchoPacket < EaseEngine::Packet
4
+ def initialize
5
+ super
6
+
7
+ packer :str
8
+ end
9
+ end
@@ -0,0 +1,48 @@
1
+ require "ease_engine"
2
+ require "./echo_packet"
3
+
4
+ class BenchmarkApplication < EaseEngine::Application
5
+ def on_start
6
+ super
7
+
8
+ @is_update = true
9
+ EaseEngine::Frame.fps = 60
10
+
11
+ host = ARGV[ 0 ]
12
+ port = ARGV[ 1 ].to_i
13
+ backlog = ARGV[ 2 ].to_i
14
+ backlog = Socket::Constants::SOMAXCONN if backlog <= 0
15
+
16
+ @tcp_socket = EaseEngine::TCPServer.new( host, port )
17
+ @tcp_socket.listen( backlog )
18
+ add_server_socket( @tcp_socket )
19
+
20
+ @udp_socket = EaseEngine::UDPSocket.new
21
+ @udp_socket.bind( host, port )
22
+ add_socket( @udp_socket )
23
+
24
+ EE_LOG_DBG.call "host=#{host} port=#{port} backlog=#{backlog} Socket::Constants::SOMAXCONN=#{Socket::Constants::SOMAXCONN}"
25
+ end
26
+
27
+ def on_update
28
+ if 1000000 <= @measure.check
29
+ EE_LOG_DBG.call "watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec} count=#{@measure.count}"
30
+
31
+ @measure.start
32
+ end
33
+ end
34
+
35
+ def on_read_socket( socket, packet )
36
+ write_packet( socket, packet, 0 )
37
+ end
38
+
39
+ def on_close_socket( socket )
40
+ case socket
41
+ when @tcp_socket
42
+ EE_LOG_DBG.call "on_close_socket #{socket}"
43
+ when @udp_socket
44
+ EE_LOG_DBG.call "on_close_socket #{socket}"
45
+ end
46
+ end
47
+ end
48
+ BenchmarkApplication::run
@@ -0,0 +1,23 @@
1
+ require "ease_engine"
2
+
3
+ class BenchmarkApplication < EaseEngine::Application
4
+ def on_start
5
+ super
6
+
7
+ @is_update = true
8
+ EaseEngine::Frame.fps = ARGV[ 0 ].to_i
9
+ end
10
+
11
+ def on_update
12
+ if 1000000 <= @measure.check
13
+ @is_update = false
14
+ end
15
+ end
16
+
17
+ def on_end
18
+ super
19
+
20
+ EE_LOG_DBG.call "fps=#{EaseEngine::Frame.fps} update_usec=#{@measure.update_usec} count=#{@measure.count}"
21
+ end
22
+ end
23
+ BenchmarkApplication::run
@@ -0,0 +1,9 @@
1
+ require "ease_engine"
2
+
3
+ response = EaseEngine::HTTP.get( "http://google.co.jp" )
4
+ p [ response, response.code ]
5
+ #p response.body
6
+
7
+ response = EaseEngine::HTTP.post( "http://google.co.jp" )
8
+ p [ response, response.code ]
9
+ #p response.body
@@ -0,0 +1,39 @@
1
+ COMPILER = gcc
2
+ override COMPILE_OPTIONS += -g -Wall -O2
3
+ override LINK_OPTIONS +=
4
+ override STATIC_LIBS +=
5
+ RM = rm -f
6
+ MKDIR = mkdir -p
7
+ MAIN_TARGET = loop_c
8
+ SRCS = loop.c
9
+ OBJ_DIR = obj
10
+ OBJS = obj/./loop.o
11
+ DEPS = obj/./loop.d
12
+
13
+ .PHONY: all obj clean
14
+
15
+ all: $(MAIN_TARGET)
16
+
17
+ obj: $(OBJS)
18
+
19
+ clean:
20
+ $(RM) $(MAIN_TARGET)
21
+ $(RM) $(OBJS)
22
+ $(RM) $(DEPS)
23
+
24
+ $(OBJ_DIR)/%.o: %.c
25
+ @[ -e $(dir $@) ] || $(MKDIR) $(dir $@)
26
+
27
+ $(COMPILER) $(COMPILE_OPTIONS) -c $< -o $@
28
+
29
+ @$(COMPILER) $(COMPILE_OPTIONS) -MM -MG -MP $< \
30
+ | sed "s/.*\.o/$(subst /,\/,$@) $(subst /,\/,$(patsubst %.o,%.d,$@))/g" > $(patsubst %.o,%.d,$@); \
31
+ [ -s $(patsubst %.o,%.d,$@) ] || $(RM) $(patsubst %.o,%.d,$@)
32
+
33
+ -include $(DEPS)
34
+
35
+ $(MAIN_TARGET): $(OBJS) $(STATIC_LIBS)
36
+ @[ -e $(dir $@) ] || $(MKDIR) $(dir $@)
37
+
38
+ $(COMPILER) $(LINK_OPTIONS) -o $@ $^
39
+
@@ -0,0 +1,11 @@
1
+ require "moon_rabbit"
2
+ include MoonRabbit
3
+
4
+ Makefile.new( "./Makefile" ){
5
+ compiler "gcc"
6
+ compile_option "-g -Wall -O2"
7
+ obj_dir "obj"
8
+
9
+ main_target "loop_c"
10
+ src "loop.c"
11
+ }.output
@@ -0,0 +1,42 @@
1
+ task :default => [ :build ]
2
+
3
+ desc "Init"
4
+ task :init do |t, args|
5
+ sh "npm install date-utils"
6
+ end
7
+
8
+ desc "Build"
9
+ task :build do |t, args|
10
+ sh "make"
11
+ sh "go build -o loop_go loop.go"
12
+ sh "scalac -d obj -optimise loop.scala"
13
+ sh "mcs -out:loop_cs loop.cs"
14
+ end
15
+
16
+ desc "Clean"
17
+ task :clean do |t, args|
18
+ sh "make clean"
19
+ sh "rm -f loop_go obj/*.class loop_cs"
20
+ end
21
+
22
+ desc "Version"
23
+ task :version do |t, args|
24
+ sh "gcc -dumpversion"
25
+ sh "go version"
26
+ sh "scala -version"
27
+ sh "node -v"
28
+ sh "mono -V|grep version"
29
+ sh "php -v|grep built"
30
+ sh "ruby -v"
31
+ end
32
+
33
+ desc "Run"
34
+ task :run do |t, args|
35
+ sh "./loop_go"
36
+ sh "./loop_c"
37
+ sh "scala loop.scala"
38
+ sh "node loop.js"
39
+ sh "mono loop_cs"
40
+ sh "php loop.php"
41
+ sh "ruby loop.rb"
42
+ end
@@ -0,0 +1,38 @@
1
+ #include <stdio.h>
2
+ #include <stdint.h>
3
+ #include <stdlib.h>
4
+ #include <stdbool.h>
5
+ #include <inttypes.h>
6
+ #include <sys/time.h>
7
+
8
+ uint64_t time_usec( struct timeval* time ){
9
+ return time->tv_sec * 1000000 + time->tv_usec;
10
+ }
11
+
12
+ int main( int argc, char* argv[] ){
13
+ int sec = 1;
14
+ if ( 1 < argc ){
15
+ sec = atoi( argv[ 1 ] );
16
+ if ( sec <= 0 ){
17
+ sec = 1;
18
+ }
19
+ }
20
+
21
+ uint64_t usec = sec * 1000000;
22
+ uint64_t count = 0;
23
+ struct timeval start_tv;
24
+ gettimeofday( &start_tv, NULL );
25
+ uint64_t start_usec = time_usec( &start_tv );
26
+ while ( true ){
27
+ count += 1;
28
+ struct timeval end_tv;
29
+ gettimeofday( &end_tv, NULL );
30
+ uint64_t end_usec = time_usec( &end_tv );
31
+ uint64_t update_usec = end_usec - start_usec;
32
+ if ( usec <= update_usec ){
33
+ printf( "count=%"PRIu64" update_usec=%"PRIu64"\n", count, update_usec );
34
+ break;
35
+ }
36
+ }
37
+ return 0;
38
+ }
@@ -0,0 +1,33 @@
1
+ using System;
2
+
3
+ class Loop {
4
+ static DateTime m_unix_epoch_base_time = new DateTime( 1970, 1, 1 );
5
+
6
+ public static UInt64 TimeUSec( DateTime utc_time ){
7
+ return (UInt64)( ( utc_time - m_unix_epoch_base_time ).TotalSeconds * 1000000 );
8
+ }
9
+
10
+ public static void Main( string[] args ){
11
+ Int32 sec = 1;
12
+ if ( 0 < args.Length ){
13
+ sec = Convert.ToInt32( args[ 0 ] );
14
+ }
15
+ if ( sec <= 0 ){
16
+ sec = 1;
17
+ }
18
+
19
+ UInt64 usec = (UInt64)sec * 1000000;
20
+ UInt64 count = 0;
21
+ UInt64 start_usec = TimeUSec( DateTime.UtcNow );
22
+ // Console.WriteLine( String.Format( "start_usec={0}", start_usec ) );
23
+ while ( true ){
24
+ count += 1;
25
+ UInt64 end_usec = TimeUSec( DateTime.UtcNow );
26
+ UInt64 update_usec = end_usec - start_usec;
27
+ if ( usec <= update_usec ){
28
+ Console.WriteLine( String.Format( "count={0} update_usec={1}", count, update_usec ) );
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "time"
6
+ "os"
7
+ "strconv"
8
+ )
9
+
10
+ func time_usec( time time.Time )( uint64 ){
11
+ return uint64( time.UnixNano() / 1000 )
12
+ }
13
+
14
+ func main(){
15
+ argc := len( os.Args )
16
+ sec := 1
17
+ if 2 <= argc {
18
+ sec, _ = strconv.Atoi( os.Args[ 1 ] )
19
+ }
20
+ usec := uint64( sec * 1000000 )
21
+
22
+ count := uint64( 0 )
23
+ start_usec := time_usec( time.Now() )
24
+ for {
25
+ count += 1
26
+ end_usec := time_usec( time.Now() )
27
+ update_usec := end_usec - start_usec
28
+ if usec <= update_usec {
29
+ fmt.Printf( "count=%d update_usec=%d\n", count, update_usec )
30
+ break
31
+ }
32
+ }
33
+ }