Advertisement
cwchen

Compare Language::Prolog::Yaswi and AI::Prolog

Sep 2nd, 2014
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.05 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use diagnostics;
  5.  
  6. use Benchmark;
  7. use AI::Prolog;
  8. use Language::Prolog::Yaswi qw(:load :query);
  9. use Language::Prolog::Sugar
  10.     vars => [qw(X Z)],
  11.     functors => {travelFromTo => 'travelFromTo'};
  12.  
  13. my $database = <<'END_PROLOG';
  14. directTrain(saarbruecken,dudweiler).
  15. directTrain(forbach,saarbruecken).
  16. directTrain(freyming,forbach).
  17. directTrain(stAvold,freyming).
  18. directTrain(fahlquemont,stAvold).
  19. directTrain(metz,fahlquemont).
  20. directTrain(nancy,metz).
  21.  
  22. travelFromTo(X,Y) :- directTrain(X,Y).
  23. travelFromTo(X,Z) :-
  24.     directTrain(X,Y),
  25.     travelFromTo(Y,Z).
  26. END_PROLOG
  27.  
  28. swi_inline <<"EOP";
  29. $database
  30. EOP
  31.  
  32. sub by_yaswi {
  33.     swi_set_query(travelFromTo(X, Z));
  34.     while (swi_next) {
  35.     swi_vars(X), swi_vars(Z);
  36.     }
  37.     return;
  38. }
  39.  
  40. my $prolog = AI::Prolog->new($database);
  41. sub by_ai_prolog {
  42.     $prolog->query("travelFromTo(X,Z).");
  43.     while (my $result = $prolog->results) {
  44.     my @results = @{$result}[1..2];
  45.     }
  46.     return;
  47. }
  48.  
  49. timethese(1000, {
  50.     "by yaswi" => 'by_yaswi()',
  51.     "by ai prolog" => "by_ai_prolog()",
  52.       });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement