7. Ring Documentation, Release 1.10
202 NewLine 5
203 PushP 007D37D8 0 207
204 AssignmentPointer
205 PushN 1.000000
206 BeforeEqual 0
207 Assignment 0 0
208 FreeStack
209 NewLine 6
210 Return
===================================================
74.5 CGI Support
Command:
ring test.ring -cgi
74.6 No Run
Command:
ring test.ring -norun
74.7 Printing Instruction Operation Code
Command:
ring test.ring -ins
Output:
===================================================
Operation : ReturnNull
PC : 1
Line Number : 1 , File test.ring
SP (After) : 0 - FuncSP : 0
LineNumber 1
===================================================
.....
.....
.....
Tip: Output removed from the previous example because it’s very large!
74.8 Performance
Command:
74.5. CGI Support 854
8. Ring Documentation, Release 1.10
ring test.ring -performance
Output:
===================================================
Date : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================
Hello World
1
2
3
4
5
6
7
8
9
10
welcome
x: 10.000000
y: 20.000000
z: 30.000000
===================================================
Date : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================
74.9 Generate Object File
You can generate object file (.ringo) from your source code file (.ring) using -go option
Tip: You will get one object file to use for distributing/running your application which may contains one or many
ring source files that you can keep or distribute based on the application (commercial or open source).
Command:
ring test.ring -go
To run the compiled object file
ring test.ringo
74.9. Generate Object File 855
9. CHAPTER
SEVENTYFIVE
PERFORMANCE TIPS
In this chapter we will learn more about the Ring performance.
75.1 Introduction
Ring is designed to be a simple, small and flexible language in the first place, but also it is fast enough for many
applications.
Ring can do each of the next tasks in around 1 second using normal computers in the market during the last 5 years
1. Compiling 100,000 lines of code
2. Executing empty loop that count from 1 to 10,000,000
3. Executing 1000 search operation using linear search in a list contains 100,000 items, trying to find the last item
(The worst case)
4. Creating list contains 1,000,000 items then summing all of the list items
5. Adding 20,000 items to the ListWidget in GUI applications
6. Adding 5,000 nodes to the TreeWidget in GUI applications
7. Printing 10,000 messages to the terminal in Console applications
Also when we need more speed we can use C/C++ extensions!
Example:
? "Create list contains 100,000 items"
aList = 1:100000
? "Do 1000 search operation - Find the last item (Worst Case!)"
c = clock()
for t = 1 to 1000
find(alist,100000)
next
? "Time: " + ( clock() - c ) / clockspersecond() + " seconds"
Output:
Create list contains 100,000 items
Do 1000 search operation - Find the last item (Worst Case!)
Time: 0.87 seconds
856
10. Ring Documentation, Release 1.10
Example:
load "guilib.ring"
func main
new qApp {
win = new qWidget() {
move(100,100) resize(500,500)
setWindowTitle("Many Tree Items - Testing Performance")
tree = new qTreeWidget(win) {
blocksignals(True) setUpdatesEnabled(False)
root = new qTreeWidgetItem()
root.setText(0,"The Root Node")
t1 = clock()
for t = 1 to 5000
oItem = new qTreeWidgetItem()
oItem.settext(0,"Item " + t)
root.addchild(oItem)
next
cTime = (clock()-t1)/clockspersecond()
setHeaderLabel("Creating 5000 nodes in " + cTime + " seconds.")
addTopLevelItem(root)
expanditem(root)
blocksignals(False) setUpdatesEnabled(True)
}
oLayout = new qVBoxLayout() {
addWidget(tree)
}
setLayout(oLayout)
show()
}
exec()
}
Output:
75.1. Introduction 857