Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2.  
  3. use Modern::Perl;
  4. use Data::Section::Simple qw(get_data_section);
  5. use File::Temp;
  6.  
  7. my $langs = get_data_section;
  8.  
  9. for my $lang (sort keys %$langs) {
  10. my $code = $langs->{$lang};
  11. my $tmp = File::Temp->new;
  12. print $tmp $code;
  13. close $tmp;
  14. chmod 0755, "$tmp";
  15.  
  16. say "--> $lang";
  17. my $out = `time -l $tmp 2>&1`;
  18. die unless $?>>8 == 0;
  19. say $out;
  20. }
  21.  
  22. my @cmd = (
  23. "uname -a",
  24. "pkg info | ack 'p5-DBD-Pg|psycopg2|rubygem-pg|pgpass|^ruby-|^perl|^python'",
  25. );
  26. for (@cmd) {
  27. say "--> $_";
  28. system($_);
  29. say "";
  30. }
  31.  
  32. __DATA__
  33.  
  34. @@ perl
  35. #!/usr/local/bin/perl
  36. use Modern::Perl;
  37. use DBI;
  38. use Time::HiRes qw(gettimeofday tv_interval);
  39. my $id = 1234;
  40. my $dbh = DBI->connect("dbi:Pg:dbname=dbname", 'user', 'pass');
  41. my $sth = $dbh->prepare('SELECT * FROM product WHERE id = ?');
  42. my @cols;
  43. $sth->execute($id) or die;
  44. $sth->bind_columns( map { \$cols[$_] } 0..28 );
  45. my $start = [gettimeofday];
  46. for (1..100000) {
  47. $sth->execute($id);
  48. $sth->fetch;
  49. die unless $cols[0] == $id;
  50. }
  51. say tv_interval($start);
  52.  
  53. @@ python
  54. #!/usr/local/bin/python2.7
  55. import psycopg2
  56. import timeit
  57. conn = psycopg2.connect("dbname=dbname user=user") # Is psycopg2 not supporting prepared?
  58. id = 1234
  59. cur = conn.cursor()
  60. if __name__ == '__main__':
  61. from time import time
  62. cur.execute("SELECT * FROM product WHERE id = %s", [id])
  63. start = time()
  64. for i in range(0,100000):
  65. cur.execute("SELECT * FROM product WHERE id = %s", [id])
  66. cols = cur.fetchone()
  67. if cols[0] != id:
  68. raise
  69. print time() - start
  70.  
  71. @@ ruby
  72. #!/usr/local/bin/ruby
  73. require 'pg'
  74.  
  75. db_conig = {
  76. host: '127.0.0.1',
  77. user: 'user',
  78. password: 'pass',
  79. dbname: 'dbname',
  80. port: '5432'
  81. }
  82. connection = PG.connect(db_conig)
  83. connection.prepare("select", 'SELECT * FROM product WHERE id = $1');
  84. result = connection.exec_prepared('select', [1234])
  85. start = Time.now
  86. 100000.times{
  87. result = connection.exec_prepared('select', [1234])
  88. val = result.values[0][0].to_i
  89. if val != 1234 then
  90. fail val
  91. end
  92. }
  93. puts Time.now - start
  94.  
  95. @@ php
  96. #!/usr/local/bin/php
  97. <?php
  98. $con = pg_connect("port=5432 user=user password=pass dbname=dbname");
  99. $result = pg_prepare($con, "my_query", 'SELECT * FROM product WHERE id = $1');
  100. $result = pg_execute($con, "my_query", array(1234));
  101. $start_time = microtime(TRUE);
  102. for ($count = 1; $count <= 100000; $count++) {
  103. $result = pg_execute($con, "my_query", array(1234));
  104. $row = pg_fetch_row($result);
  105. if ( $row[0] != 1234 ) {
  106. die;
  107. }
  108. }
  109. print microtime(TRUE)-$start_time . "\n";
  110. ?>
  111.  
  112. __END__
  113.  
  114. --> perl
  115. 4.034649
  116. 4.06 real 0.66 user 0.28 sys
  117. 11796 maximum resident set size
  118. 7 average shared memory size
  119. 3 average unshared data size
  120. 113 average unshared stack size
  121. 1432 page reclaims
  122. 0 page faults
  123. 0 swaps
  124. 4 block input operations
  125. 0 block output operations
  126. 100005 messages sent
  127. 100004 messages received
  128. 0 signals received
  129. 100006 voluntary context switches
  130. 4 involuntary context switches
  131.  
  132. --> php
  133. 3.8969540596008
  134. 3.90 real 0.50 user 0.27 sys
  135. 8180 maximum resident set size
  136. 3417 average shared memory size
  137. 153 average unshared data size
  138. 108 average unshared stack size
  139. 508 page reclaims
  140. 0 page faults
  141. 0 swaps
  142. 4 block input operations
  143. 0 block output operations
  144. 100004 messages sent
  145. 100003 messages received
  146. 0 signals received
  147. 100005 voluntary context switches
  148. 1 involuntary context switches
  149.  
  150. --> python
  151. 10.5168910027
  152. 10.55 real 3.42 user 0.30 sys
  153. 15904 maximum resident set size
  154. 4 average shared memory size
  155. 4 average unshared data size
  156. 128 average unshared stack size
  157. 2603 page reclaims
  158. 0 page faults
  159. 0 swaps
  160. 2 block input operations
  161. 0 block output operations
  162. 100004 messages sent
  163. 100003 messages received
  164. 0 signals received
  165. 100005 voluntary context switches
  166. 26 involuntary context switches
  167.  
  168. --> ruby
  169. 4.696169619
  170. 4.74 real 0.77 user 0.38 sys
  171. 16932 maximum resident set size
  172. 3 average shared memory size
  173. 3 average unshared data size
  174. 124 average unshared stack size
  175. 2766 page reclaims
  176. 0 page faults
  177. 0 swaps
  178. 6 block input operations
  179. 0 block output operations
  180. 100005 messages sent
  181. 100004 messages received
  182. 0 signals received
  183. 100010 voluntary context switches
  184. 15 involuntary context switches
  185.  
  186. --> uname -a
  187. FreeBSD 11.0-RELEASE-p9 FreeBSD 11.0-RELEASE-p9 #0: Tue Apr 11 08:48:40 UTC 2017 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
  188.  
  189. --> pkg info | ack 'p5-DBD-Pg|psycopg2|rubygem-pg|pgpass|^ruby-|^perl|^python'
  190. p5-DBD-Pg-3.6.0 Provides access to PostgreSQL databases through the DBI
  191. perl5-5.24.1_1 Practical Extraction and Report Language
  192. php71-pgpass-7.1.5 The pgpass shared extension for php
  193. py27-psycopg2-2.7.1 High performance Python adapter for PostgreSQL
  194. python27-2.7.13_3 Interpreted object-oriented programming language
  195. ruby-2.3.4,1 Object-oriented interpreted scripting language
  196. rubygem-pg-0.20.0 Ruby interface to PostgreSQL library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement