| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The Perl Foundation. Consult the "LICENSE.txt" file for details. |
|---|
| 9 | ================================================================ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | To load this example and for sample queries, please see the SCRIPT.txt file. |
|---|
| 13 | |
|---|
| 14 | This folder provides simple benchmark tests for comparing Logtalk message |
|---|
| 15 | sending performance with direct predicates calls in plain Prolog. |
|---|
| 16 | These benchmarks may also be used for comparing Logtalk message sending |
|---|
| 17 | performance across Prolog compilers. |
|---|
| 18 | |
|---|
| 19 | This example is made of four loader files and five source files: |
|---|
| 20 | |
|---|
| 21 | loader_events.lgt |
|---|
| 22 | loads all source files with event support turned on |
|---|
| 23 | loader_no_events.lgt |
|---|
| 24 | loads all source files with event support turned off |
|---|
| 25 | loader_static_binding.lgt |
|---|
| 26 | loads all source files with event support turned off and using |
|---|
| 27 | static binding |
|---|
| 28 | loader.lgt |
|---|
| 29 | the same as the loader_static_binding.lgt file |
|---|
| 30 | |
|---|
| 31 | benchmarks.lgt |
|---|
| 32 | contains the benchmark goals and testing predicates |
|---|
| 33 | plain.lgt |
|---|
| 34 | contains a definition for a list length predicate and a predicate |
|---|
| 35 | for testing performance of the built-in predicates assertz/1 and |
|---|
| 36 | retract/1 |
|---|
| 37 | module.pl (not loaded by default; see below) |
|---|
| 38 | contains the same definition of a list length predicate |
|---|
| 39 | encapsulated in a module |
|---|
| 40 | objects.lgt |
|---|
| 41 | contains an object encapsulating the same definition of a list |
|---|
| 42 | length predicate, plus two descendant objects to simulate a small |
|---|
| 43 | hierarchy (used for testing calls to imported category predicates) |
|---|
| 44 | database.lgt |
|---|
| 45 | contains predicates for testing the performance of the built-in |
|---|
| 46 | database methods assertz/1 and retract/1 |
|---|
| 47 | category.lgt |
|---|
| 48 | contains a single predicate used when comparing performance of |
|---|
| 49 | calls to imported category predicates using direct calls and using |
|---|
| 50 | messages to "self" |
|---|
| 51 | |
|---|
| 52 | You may have noticed above that the benchmark predicates and the predicates |
|---|
| 53 | for plain Prolog testing are both encapsulated in Logtalk source files. The |
|---|
| 54 | Logtalk compiler just copies the plain Prolog code to the generated Prolog |
|---|
| 55 | files. The reason for using the .lgt extension for these files is simply to |
|---|
| 56 | make it possible to load all the example code using calls to the predicates |
|---|
| 57 | logtalk_load/1-2. |
|---|
| 58 | |
|---|
| 59 | By default, the benchmark tests on the SCRIPT file use a list of 20 elements |
|---|
| 60 | as an argument to the list length predicates. When dynamic binding is used, |
|---|
| 61 | increasing the list length leads to decreasing performance differences between |
|---|
| 62 | plain Prolog and Logtalk as the list length computation time far outweighs the |
|---|
| 63 | overhead of the message sending mechanism. Likewise, decreasing the list |
|---|
| 64 | length leads to increasing performance differences between plain Prolog and |
|---|
| 65 | Logtalk (up to the point you will be measuring the Logtalk message sending |
|---|
| 66 | mechanism overhead compared to plain Prolog predicate calls). In real-life |
|---|
| 67 | applications, only testing can give you a balanced view on the trade-offs |
|---|
| 68 | between plain Prolog performance and Logtalk programming features. |
|---|
| 69 | |
|---|
| 70 | By default, the loader files used to load the example code do not load the |
|---|
| 71 | module.pl file. Edit these files if your Prolog compiler supports a module |
|---|
| 72 | system and you want to run some comparative performance tests between plain |
|---|
| 73 | Prolog, Prolog modules, and Logtalk objects. Note that you may need to edit |
|---|
| 74 | the code on the module.pl file to make any necessary compatibility changes |
|---|
| 75 | for your Prolog compiler module system. For most Prolog module systems, the |
|---|
| 76 | performance of module calls is close or even identical to the performance of |
|---|
| 77 | plain Prolog calls when using imported predicates and implicit qualification. |
|---|
| 78 | When using explicit module qualification, performance can be significantly |
|---|
| 79 | worse. |
|---|
| 80 | |
|---|
| 81 | When static binding is used, messages to objects are, whenever possible, |
|---|
| 82 | translated to direct predicate calls. Thus performance should be about the |
|---|
| 83 | same as in plain Prolog predicate calls. However, due to the overhead of |
|---|
| 84 | three extra arguments per object predicate (used for passing the execution |
|---|
| 85 | context), the performance of Logtalk optimized calls might be slightly |
|---|
| 86 | worse than the equivalent plain Prolog predicate calls. |
|---|