ease_engine 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,23 @@
1
+ require ( "date-utils" );
2
+
3
+ function time_usec( time ){
4
+ return time * 1000;
5
+ }
6
+
7
+ var sec = 1;
8
+ if ( 3 <= process.argv.length ){
9
+ sec = parseInt( process.argv[ 2 ] );
10
+ }
11
+ var usec = sec * 1000000;
12
+
13
+ var count = 0;
14
+ var start_usec = time_usec( Date.now() );
15
+ while ( true ){
16
+ count += 1;
17
+ var end_usec = time_usec( Date.now() );
18
+ var update_usec = end_usec - start_usec;
19
+ if ( usec <= update_usec ){
20
+ console.log( "count="+ count +" update_usec="+ update_usec );
21
+ break;
22
+ }
23
+ }
@@ -0,0 +1,22 @@
1
+ <?php
2
+ function time_usec( $time ){
3
+ return $time * 1000000;
4
+ }
5
+
6
+ $sec = isset( $argv[ 1 ] ) ? intval( $argv[ 1 ] ) : 1;
7
+ if ( $sec <= 0 ){
8
+ $sec = 1;
9
+ }
10
+ $usec = $sec * 1000000;
11
+
12
+ $count = 0;
13
+ $start_usec = time_usec( microtime( true ) );
14
+ while ( true ){
15
+ $count += 1;
16
+ $end_usec = time_usec( microtime( true ) );
17
+ $update_usec = $end_usec - $start_usec;
18
+ if ( $usec <= $update_usec ){
19
+ printf( "count=%u update_usec=%u\n", $count, $update_usec );
20
+ break;
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ def time_usec( time )
2
+ time.to_i * 1000000 + time.usec
3
+ end
4
+
5
+ sec = ARGV[ 0 ].to_i
6
+ sec = 1 if sec <= 0
7
+ usec = sec * 1000000
8
+
9
+ count = 0
10
+ start_usec = time_usec( Time.new )
11
+ while true
12
+ count += 1
13
+ end_usec = time_usec( Time.new )
14
+ update_usec = end_usec - start_usec
15
+ if usec <= update_usec
16
+ puts "count=#{count} update_usec=#{update_usec}"
17
+ break
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ import scala.util.control.Breaks.{ breakable, break }
2
+
3
+ object loop {
4
+ def time_usec( time: Long ): Long = {
5
+ time * 1000
6
+ }
7
+
8
+ def main( args: Array[ String ] ){
9
+ var argc = args.size
10
+ var sec = 1
11
+ if ( 1 <= argc ){
12
+ sec = Integer.parseInt( args( 0 ) )
13
+ }
14
+ var usec = sec * 1000000
15
+
16
+ var count = 0
17
+ var start_usec = time_usec( System.currentTimeMillis() )
18
+ breakable {
19
+ while ( true ){
20
+ count += 1
21
+ var end_usec = time_usec( System.currentTimeMillis() )
22
+ var update_usec = end_usec - start_usec
23
+ if ( usec <= update_usec ){
24
+ printf( "count=%d update_usec=%d\n", count, update_usec )
25
+ break
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
Binary file
Binary file
Binary file
@@ -0,0 +1,76 @@
1
+ require "ease_engine"
2
+
3
+ class BenchmarkApplication < EaseEngine::Application
4
+ def on_start
5
+ super
6
+
7
+ EaseEngine::Frame.fps = 60
8
+
9
+ host = ARGV[ 0 ]
10
+ port = ARGV[ 1 ].to_i
11
+ @tcp_num = ARGV[ 2 ].to_i
12
+ @udp_num = ARGV[ 3 ].to_i
13
+
14
+ @tcp_num.times{|i|
15
+ tcp_socket = EaseEngine::TCPSocket.new( host, port )
16
+ # EE_LOG_DBG.call "tcp_num=#{i + 1}"
17
+ add_connect_socket( tcp_socket )
18
+ }
19
+
20
+ measure_packet = EaseEngine::MeasurePacket.new
21
+
22
+ @udp_num.times{|i|
23
+ udp_socket = EaseEngine::UDPSocket.new
24
+ # EE_LOG_DBG.call "udp_num=#{i + 1}"
25
+ add_socket( udp_socket )
26
+ measure_packet.start
27
+ write_packet( udp_socket, measure_packet, 0, host, port )
28
+ }
29
+
30
+ @measure.check
31
+ 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}"
32
+ @measure.start
33
+
34
+ @is_update = ( 0 < @watcher.size )
35
+
36
+ @measure_read_socket = EaseEngine::Measure.new
37
+ end
38
+
39
+ def on_update
40
+ if 1000000 <= @measure.check
41
+ EE_LOG_DBG.call "tcp_num=#{@tcp_num} udp_num=#{@udp_num} watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec} count=#{@measure.count}"
42
+
43
+ @measure.start
44
+ @is_update = ( 0 < @watcher.size )
45
+ end
46
+ end
47
+
48
+ def on_end
49
+ super
50
+
51
+ @measure_read_socket.check
52
+ EE_LOG_DBG.call "update_usec=#{@measure_read_socket.update_usec}"
53
+ end
54
+
55
+ def on_connected_socket( socket )
56
+ write_packet( socket, EaseEngine::MeasurePacket.new, 0 )
57
+ end
58
+
59
+ def on_read_socket( socket, packet )
60
+ send( "on_#{packet.packet_name.gsub( /\./, '_' )}", socket, packet )
61
+ end
62
+
63
+ def on_EaseEngine_MeasurePacket( socket, packet )
64
+ if socket.kind_of?( EaseEngine::TCPSocket )
65
+ @tcp_num -= 1
66
+ else
67
+ @udp_num -= 1
68
+ end
69
+
70
+ EE_LOG_DBG.call "MeasurePacket usec=#{packet.check} #{socket}"
71
+ remove_socket( socket )
72
+
73
+ @is_update = false if 0 == @watcher.size
74
+ end
75
+ end
76
+ BenchmarkApplication::run
@@ -0,0 +1,47 @@
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 = 60
9
+
10
+ host = ARGV[ 0 ]
11
+ port = ARGV[ 1 ].to_i
12
+ backlog = ARGV[ 2 ].to_i
13
+ backlog = Socket::Constants::SOMAXCONN if backlog <= 0
14
+
15
+ @tcp_socket = EaseEngine::TCPServer.new( host, port )
16
+ @tcp_socket.listen( backlog )
17
+ add_server_socket( @tcp_socket )
18
+
19
+ @udp_socket = EaseEngine::UDPSocket.new
20
+ @udp_socket.bind( host, port )
21
+ add_socket( @udp_socket )
22
+
23
+ EE_LOG_DBG.call "host=#{host} port=#{port} backlog=#{backlog} Socket::Constants::SOMAXCONN=#{Socket::Constants::SOMAXCONN}"
24
+ end
25
+
26
+ def on_update
27
+ if 1000000 <= @measure.check
28
+ EE_LOG_DBG.call "watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec} count=#{@measure.count}"
29
+
30
+ @measure.start
31
+ end
32
+ end
33
+
34
+ def on_read_socket( socket, packet )
35
+ write_packet( socket, packet, 0 )
36
+ end
37
+
38
+ def on_close_socket( socket )
39
+ case socket
40
+ when @tcp_socket
41
+ EE_LOG_DBG.call "on_close_socket #{socket}"
42
+ when @udp_socket
43
+ EE_LOG_DBG.call "on_close_socket #{socket}"
44
+ end
45
+ end
46
+ end
47
+ BenchmarkApplication::run
@@ -0,0 +1,3 @@
1
+ require "ease_engine"
2
+
3
+ p EaseEngine::Process.execute( "ls" )
@@ -0,0 +1,45 @@
1
+ require "ease_engine"
2
+
3
+ class BenchmarkApplication < EaseEngine::Application
4
+ def on_start
5
+ super
6
+
7
+ EaseEngine::Frame.fps = 60
8
+
9
+ host = ARGV[ 0 ]
10
+ port = ARGV[ 1 ].to_i
11
+ @tcp_num = ARGV[ 2 ].to_i
12
+ @connected_tcp_num = 0
13
+
14
+ @tcp_num.times{
15
+ add_connect_socket( EaseEngine::TCPSocket.new( host, port ) )
16
+ }
17
+ EE_LOG_DBG.call "host=#{host} port=#{port} tcp_num=#{@tcp_num} watcher.size=#{@watcher.size}"
18
+
19
+ @measure = EaseEngine::Measure.new
20
+ @measure_update = EaseEngine::Measure.new
21
+
22
+ @is_update = ( 0 < @tcp_num )
23
+ end
24
+
25
+ def on_connected_socket( socket )
26
+ @connected_tcp_num += 1
27
+
28
+ @is_update = false if @tcp_num <= @connected_tcp_num
29
+ end
30
+
31
+ def on_update
32
+ if 1000000 <= @measure_update.check
33
+ EE_LOG_DBG.call "update_usec=#{@measure_update.update_usec} count=#{@measure_update.count} tcp_num=#{@tcp_num} connected_tcp_num=#{@connected_tcp_num}"
34
+ @measure_update.start
35
+ end
36
+ end
37
+
38
+ def on_end
39
+ super
40
+
41
+ @measure.check
42
+ EE_LOG_DBG.call "update_usec=#{@measure.update_usec}"
43
+ end
44
+ end
45
+ BenchmarkApplication::run
@@ -0,0 +1,40 @@
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 = 60
9
+
10
+ host = ARGV[ 0 ]
11
+ port = ARGV[ 1 ].to_i
12
+ backlog = ARGV[ 2 ].to_i
13
+ backlog = Socket::Constants::SOMAXCONN if backlog <= 0
14
+
15
+ @tcp_socket = EaseEngine::TCPServer.new( host, port )
16
+ @tcp_socket.listen( backlog )
17
+ add_server_socket( @tcp_socket )
18
+
19
+ EE_LOG_DBG.call "host=#{host} port=#{port} backlog=#{backlog} Socket::Constants::SOMAXCONN=#{Socket::Constants::SOMAXCONN}"
20
+ end
21
+
22
+ def on_update
23
+ if 1000000 <= @measure.check
24
+ EE_LOG_DBG.call "watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec} count=#{@measure.count}"
25
+ @measure.start
26
+ end
27
+ end
28
+
29
+ def on_read_socket( socket, packet )
30
+ remove_socket( socket )
31
+ end
32
+
33
+ def on_close_socket( socket )
34
+ case socket
35
+ when @tcp_socket
36
+ EE_LOG_DBG.call "on_close_socket #{socket}"
37
+ end
38
+ end
39
+ end
40
+ BenchmarkApplication::run
@@ -0,0 +1,84 @@
1
+ require "ease_engine"
2
+ require "./udp_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
+ udp_num = 1
13
+
14
+ @base_data_array = [
15
+ 0,
16
+ 1,
17
+ -1,
18
+ "str",
19
+ "あいう",
20
+ 0.0,
21
+ 1.5,
22
+ -1.5,
23
+ true,
24
+ false,
25
+ nil
26
+ ]
27
+
28
+ base_data_packet = BaseDataPacket.new
29
+ base_data_packet.array = @base_data_array
30
+
31
+ parent_packet = UDP::ParentPacket.new
32
+ parent_packet.parent = 0
33
+
34
+ child_packet = UDP::ChildPacket.new
35
+ child_packet.child = 1
36
+
37
+ grandchild_packet = UDP::GrandchildPacket.new
38
+ grandchild_packet.grandchild = 2
39
+
40
+ udp_num.times{
41
+ socket = EaseEngine::UDPSocket.new
42
+ add_socket( socket )
43
+ write_packet( socket, base_data_packet, 0, host, port )
44
+ write_packet( socket, parent_packet, 0, host, port )
45
+ write_packet( socket, child_packet, 0, host, port )
46
+ write_packet( socket, grandchild_packet, 0, host, port )
47
+ }
48
+
49
+ @measure.check
50
+ EE_LOG_DBG.call "host=#{host} port=#{port} udp_num=#{udp_num} watcher.size=#{@watcher.size} update_usec=#{@measure.update_usec}"
51
+ @measure.start
52
+
53
+ @is_update = ( 0 < @watcher.size )
54
+ end
55
+
56
+ def on_end
57
+ super
58
+
59
+ @measure.check
60
+ EE_LOG_DBG.call "update_usec=#{@measure.update_usec}"
61
+ end
62
+
63
+ def on_read_socket( socket, packet )
64
+ send( "on_#{packet.packet_name.gsub( /\./, '_' )}", socket, packet )
65
+ end
66
+
67
+ def on_BaseDataPacket( socket, packet )
68
+ EE_LOG_DBG.call "#{packet.array}"
69
+ EaseEngine.assert( @base_data_array == packet.array, "#{@base_data_array} != #{packet.array}" )
70
+ end
71
+
72
+ def on_UDP_ParentPacket( socket, packet )
73
+ EE_LOG_DBG.call "#{packet}"
74
+ end
75
+
76
+ def on_UDP_ChildPacket( socket, packet )
77
+ EE_LOG_DBG.call "#{packet}"
78
+ end
79
+
80
+ def on_UDP_GrandchildPacket( socket, packet )
81
+ EE_LOG_DBG.call "#{packet}"
82
+ end
83
+ end
84
+ BenchmarkApplication::run
@@ -0,0 +1,40 @@
1
+ require "ease_engine"
2
+
3
+ class BaseDataPacket < EaseEngine::Packet
4
+ def initialize
5
+ super
6
+
7
+ packer :array
8
+ end
9
+ end
10
+
11
+ module UDP
12
+ class ParentPacket < EaseEngine::Packet
13
+ attr_accessor :type
14
+
15
+ def initialize
16
+ super
17
+
18
+ packer :parent
19
+ @type = "parent"
20
+ end
21
+ end
22
+
23
+ class ChildPacket < ParentPacket
24
+ def initialize
25
+ super
26
+
27
+ packer :child
28
+ @type = "child"
29
+ end
30
+ end
31
+
32
+ class GrandchildPacket < ChildPacket
33
+ def initialize
34
+ super
35
+
36
+ packer :grandchild
37
+ @type = "grandchild"
38
+ end
39
+ end
40
+ end