1s cycle transition to the next iteration. Cycle interruptions. combining conditions. Hotkeys: form management

December 12, 2014 at 01:13 pm

Which cycle is faster? Testing 1C

  • High performance ,
  • Abnormal programming,
  • Programming

I've been programming 1C for several years now, and then the thought came to me - “Should I take some kind of training course, what if there are some gaps in my knowledge that I didn’t even suspect about before?” No sooner said than done. I’m sitting, listening to the course, I get to cyclic operators and then the second thought (yes, they don’t come to me often) - “Which cycle is faster”? We should check it out.
So I found five ways, how you can organize a cycle using 1C.

The first type of cycle, let's call it conditionally "ForPo" looks like that:

For n = 0 by Number of Iterations Cycle SomeActions(); EndCycle;
Second type "For each":

For Each Collection Element from the Collection Cycle SomeActions(); EndCycle;
Third "Bye":

Bye<>Number of Iterations Cycle SomeActions(); n = n + 1; EndCycle;
Then I remembered my assembler youth - a cycle "If":

~Start of Cycle: If n<>Number of Iterations Then SomeActions(); n = n + 1; Go ~StartCycle; endIf;
And finally "Recursion"

Procedure RecursiveLoop(n, Number of Iterations) SomeActions(); If n<>NumberIterations Then RecursiveLoop(n+1, NumberIterations); endIf; End of Procedure
Naturally, it is not entirely correct to classify recursion as loops, but nevertheless, with its help you can achieve similar results. Let me make a reservation right away that recursion was not involved in further testing. Firstly, all tests were carried out with 1,000,000 iterations, and recursion occurs already at 2,000. Secondly, the speed of recursion is tens of times less than the speed of other loops.

Last retreat. One of the conditions was to perform some actions in the loop. Firstly, the empty loop is used very rarely. Secondly, the “ForEveryone” cycle is used for some collection, which means that other cycles must work with the collection so that testing takes place under the same conditions.

Well, let's go. The body of the loop was reading from a pre-filled array.


or, when using the “ForEach” loop

TestValueReceiver = Element;
Testing was carried out on platform 8.3.5.1231 for three types of interface ( Regular application, Managed Application and Taxi).
The numbers are the time in milliseconds obtained using the function CurrentUniversalDateInMilliseconds(), which I called before the loop and after it completed. The numbers are fractional because I used the arithmetic average of five measurements. Why didn't I use Performance Measurement? I had no goal to measure the speed of each line of code, only the speed of cycles with the same result.

It would seem that’s all, but - test, test!
Result for platform 8.2.19.106
On average, platform 8.2 is 25% faster than 8.3. I didn't expect such a difference and decided to test it on another machine. I won’t give the results, but you can generate them yourself using this configuration. I’ll just say that 8.2 was 20 percent faster.

Why? I don’t know, disassembling the kernel was not part of my plans, but I still looked at the performance measurement. It turned out that the cyclic operations themselves are somewhat faster in 8.3 than in 8.2. But on the line
TestValueReceiver = TestArray.Get(n);
that is, there is a significant performance hit when reading a collection element into a variable.

Eventually:
What is all this for? I made several conclusions for myself:

1. If it is possible to use a specialized cycle - “For Everyone”, then it is better to use it. By the way, it itself takes longer to complete than other loops, but its access speed to a collection element is much higher.
2. If you know the number of iterations in advance, use “ForPo”. “For now” will work slower.
3. If you use the “If” loop, other programmers will clearly not understand you.

21
//The function generates an easy-to-read representation of values. // Examples of number formatting ValueFormat = Format(123456.789, " NRT=10; NRT=2"); //ValueFormat = "123,456.79"ValueFormat = Format(123456.789, "HH=0; NHV=2"); //Value 16
Full text search - will allow you to find text information, placed almost anywhere in the configuration used. In this case, you can search for the necessary data either throughout the entire configuration as a whole, or by narrowing... 8
"Point in time" is a virtual field, not stored in the database. Contains a Point in Time object (which includes a date and a LINK TO A DOCUMENT) In 7.7 there was the concept of Document Position, and in 8.x Point in Time To get... 6
For 8.x FindByLinks (FindDataByRef) Syntax: FindByLinks (List of Links) Parameters: List of Links Required Type: Array. An array with a list of links to objects whose links need to be found. ...

In this article we will consider such a construction of the 1C programming language as Cycles.

There are three ways to organize loops.

  1. Loops using a logical expression (executed until logical expression true)
  2. Looping through collections

Let's look at each of these methods.

Loops using a loop counter variable

Syntax:

For< Переменная> = < НачальноеЗначение>By< КонечноеЗначение>CycleEndCycle;

With this method of organizing loops, a counter variable is assigned a certain initial value and it is executed as long as the value of the counter variable is less than or equal to the specified final value.

With each iteration, the counter value increases by one. Here is the most basic example of such a loop:

For Counter = 0 To 1000 Cycle EndCycle;

Unlike many other programming languages, 1C does not provide the ability to specify a step in a cycle. If necessary, this can be done by adding the desired value to the counter inside the loop

For Counter = 0 To 1000 Cycle Counter = Counter + 10 ; EndCycle ;

Loops Using Boolean Expressions

Syntax:

Bye< ЛогическоеВыражение>CycleEndCycle;

Refuse = False ; GeneratorRandom = NewRandomNumberGenerator(1) ; Until Failure Cycle RandomNumber = GeneratorRank. RandomNumber(0, 10); If RandomNumber > 5 Then Failure = True ; EndIf ; EndCycle ;

That is, the loop will run until a random number greater than five is generated.

Looping through collections

In the 1C programming language there is such a thing as a collection. It is a set of elements contained within an object.

We can include such objects as a collection: an array, a table of values, a selection from a query result, metadata, etc. This concept is quite conventional, but it appears at every step in the syntax assistant. Very often we encounter a task when we need to sequentially iterate through all the elements of a collection in order to perform some actions on them. That's why it exists syntactic construction:

For each< ЭлементКоллекции>From< Коллекция>CycleEndCycle;

Here <ЭлементКоллекции> is a variable into which elements from the collection are sequentially placed. And inside the loop it is processed accordingly.
As an example, I’ll give you a loop of traversing the rows of a table of values. Let it be called TableProducts and looks like this:

Let's go through this table in a loop and for each row we will display a message with the name and price of the product:

For each Table Row From Table Products Cycle Name = Table Row. Name; Price = TableRow. Price; Message = New MessageToUser; Message. Text = "Name of product: "

In fact, the same thing can be done using the first option, that is, in a loop using a counter:

Number of Rows = TableProducts. Quantity() ; For Counter = 0 By Number of Rows - 1 Cycle Table Row = TableProducts[ Counter] ; Name = Table Row. Name; Price = TableRow. Price; Message = New MessageToUser; Message. Text = "Name of product: "+ Name + "; Price: " + Price; Message. To report() ; EndCycle ;

But as we can see, using traversal of collection elements is much simpler and more convenient

Auxiliary Operators

There is often a situation where, depending on something, it is necessary to interrupt the execution of a loop or move on from the next iteration.

Interruption is carried out using the operator Abort. In this case, the execution of the loop is interrupted and control is transferred to the language construct that follows the loop. If you need to move to the next iteration, you must use the operator Continue. Then control is transferred to the beginning of the loop. Let's illustrate with a small example:

For Counter = 0 By 100 Cycle If Counter = 0 Then Continue ; EndIf ; If Counter = 4 Then Abort ; EndIf ; Result = 1 / Counter; Message = New MessageToUser; Message. Text = String(Result) ; Message. To report() ; EndCycle ;

We skip zero, because You cannot divide by zero. And the loop will be executed five times in total, for the values ​​of the variable Counter from 0 to 4

Each 1C solution on the 1C:Enterprise 8 platform has a wide range of capabilities. However, there are universal techniques that can be used in any configuration. With this article we are opening a series of publications in which 1C methodologists will talk about the universal capabilities of the 1C:Enterprise 8 platform. Let's start with one of the most important methods for increasing work efficiency - with a description of “hot” keys (actions from the keyboard, as a rule, are performed faster than those through the menu using the mouse). Having mastered the hotkeys, you will simplify the execution of frequently repeated actions.

Table 1

Action

Keyboard shortcuts

How the program works

Create new document

Open an existing document

Open calculator

Opens the calculator

Show properties

Alt+Enter
Ctrl+E

Open message window

Close message window

Ctrl + Shift + Z

Open scoreboard

Opens the scoreboard

Open help

Opens help

Call up help index

Shift + Alt + F1

Calls up the help index

Hotkeys: global actions

Global actions are actions that you can perform in any program state. It doesn’t matter what this moment open in 1C:Enterprise. The main thing is that the application is not busy performing any task.

Global actions are actions that can be called anywhere in the running 1C:Enterprise 8 platform. Regardless of what exactly happens in running configuration, the meaning of global actions does not change (for example, pressing Ctrl+N will always bring up the dialog for creating a new document).

Table 1

Hotkeys for global actions

Action

Keyboard shortcuts

How the program works

Create a new document

Opens a window in which you will be asked to select the type of new document to be created in various formats- for example, in text, table or HTML

Open an existing document

Opens the standard "Open" dialog box, accessible through the "File/Open…" menu

Activating the search field in the command bar

Places the cursor in this field

Open calculator

Opens the calculator

Show properties

Alt+Enter
Ctrl+E

Depending on what the cursor is placed on, it opens the corresponding properties palette for this object or element. Useful when working with tables, text, HTML, etc.

Open message window

Allows you to open a previously closed message window. It is often useful when a window is accidentally closed and you need a message from it. Please note: as long as the system has not entered anything into the message window again, old messages are retained even if the window is closed

Close message window

Ctrl + Shift + Z

Closes the message window when it is no longer needed. Please note: the combination is chosen so that it can be easily pressed with one hand

Open scoreboard

Opens the scoreboard

Open help

Opens help

Call up help index

Shift + Alt + F1

Calls up the help index

Hotkeys: general actions

General actions- actions that have the same meaning in different configuration objects, but the behavior of the 1C:Enterprise 8 platform changes depending on where exactly you use this or that general action. For example, pressing the "Del" key marks the current directory element for deletion if you are in the list of directory elements window. Or deletes the contents of the current cell of a spreadsheet document if you are editing it.

table 2

Hotkeys for common actions

Action

Keyboard shortcuts

How the program works

Deletes the element under the cursor (current element) or the selected group of elements

Add

Allows you to add a new element

Saves the active document

Print the active document

Calls up the print dialog for the active document

Printing to the current printer

Ctrl + Shift + P

Initiates direct printing of the active document to the default printer assigned in the system (without opening the print dialog)

Copy to clipboard

Ctrl+C
Ctrl + Ins

Copies the required element or selected group of elements to the Windows clipboard

Cut to clipboard

Ctrl+X
Shift + Del

Cuts the required element or selected group of elements to the Windows clipboard. Differs from copying in that the copied element or group is deleted after entering the buffer

Paste from clipboard

Ctrl+V
Shift + Ins

Pastes existing data from the Windows clipboard into the location marked by the cursor.

Add to clipboard as number

Shift + Num + (*)

Used for numeric values

Add to clipboard

Shift + Num + (+)

Used for numeric values. Addition operation with data on the clipboard

Subtract from clipboard

Shift + Num + (-)

Used for numeric values. Subtraction operation with data on the clipboard

Select all

Cancel last action

Ctrl+Z
Alt+BackSpace

Revert undone action

Ctrl+Y
Shift + Alt + BackSpace

Find next

Find next highlighted

Find previous

Find previous selection

Ctrl + Shift + F3

Replace

Ctrl + Num + (-)

Select all

Selects all available elements in the active document

Undo last action

Ctrl+Z
Alt+BackSpace

Undoes the last action taken

Revert undone action

Ctrl+Y
Shift + Alt + BackSpace

Allows you to undo “Ctrl + Z”, in other words - to return what you did before pressing undo the last action taken

Opens a dialog for setting search parameters in the active configuration object and performing this search

Find next

Finds the next element that matches the parameters specified in the search settings

Find next highlighted

Finds the next element that matches the one you selected (for example, where the cursor is placed)

Find previous

Finds the previous element that matches the parameters specified in the search settings

Find previous selection

Ctrl + Shift + F3

Finds the previous element matching the one you selected

Replace

Opens the Find and Replace Values ​​dialog (where allowed)

Collapse (tree node, spreadsheet document group, module grouping)

Ctrl + Num + (-)

Used where tree nodes marked with "+" or "-" are available

Collapse (tree node, spreadsheet document group, module grouping) and all subordinates

Ctrl + Alt + Num + (-)

Collapse (all tree nodes, spreadsheet document groups, module groupings)

Ctrl + Shift + Num + (-)

Expand (tree node, spreadsheet document group, module grouping)

Ctrl + Num + (+)

Expand (tree node, spreadsheet document group, module grouping) and all subordinates

Ctrl + Alt + Num + (+)

Expand (all tree nodes, spreadsheet document groups, module groupings)

Ctrl + Shift + Num + (+)

Next page

Ctrl + Page Down
Ctrl + Alt + F

Quickly scroll through the active document

Previous page

Ctrl + Page Up
Ctrl + Alt + B

Enable/disable fat content

Used where text formatting is supported and possible

Enable/disable italics

Enable/disable underlining

Go to previous web page/help chapter

Used in HTML documents

Go to next web page/help chapter

Abort execution of a data composition system report

Hotkeys: window management

This section combines hotkeys common to all windows and forms of the 1C:Enterprise platform.

Table 3

Hotkeys for managing windows

Action

Keyboard shortcuts

How the program works

Close an active free window, modal dialog, or application

This combination can quickly complete the entire configuration on the 1C:Enterprise platform, so use it carefully

Close active regular window

Closes the current normal window

Close active window

Closes the currently active window

Activate the next regular window

Ctrl+Tab
Ctrl+F6

Allows you to activate the following window among those open within the configuration. Pressing in a cycle while holding the Ctrl key allows you to scroll through open windows “forward”

Activate previous normal window

Ctrl + Shift + Tab
Ctrl + Shift + F6

Allows you to activate the previous window among those open within the configuration. Pressing in a cycle while holding the Ctrl key allows you to scroll through open windows "back"

Activate the next section of the window

Activates the next section of the current window

Activate previous window section

Activates the previous section of the current window

Call the system menu of an application or modal dialog

Allows you to see the system menu of operations (minimize, move, close, etc.) above the program window or open modal dialog

Call the window system menu (except for modal dialogs)

Alt + Hyphen + (-)
Alt + Num + (-)

Allows you to see the system menu of operations (minimize, move, close, etc.) above the active window

Call main menu

Activates the main panel with buttons for the current window. This way you can select actions without using the mouse

Call context menu

Displays a context menu above the currently active element. Same as pressing right button mouse on it

Return activity to normal window

Returns activity to the normal window after working with the context menu. Attention! In any other case, Esc initiates closing of the active window

Hotkeys: form management

Here are collected "hot" keys that simplify and speed up work with various forms that were created in configurations written on the 1C:Enterprise platform.

Table 4

Hotkeys for managing forms

Action

Keyboard shortcuts

How the program works

Move to next control/call default button

Move between controls on the form "forward" (see Tab)

Calling the default button

As a rule, different forms have a default button assigned (it is different from others - for example, it is highlighted in bold). Using this key combination allows you to open form activate default button

Move to next control

Navigate between controls on a forward form

Go to previous control

Moving between controls on the form "back"

Activates the command bar associated with the active control/form

Activates the main panel with buttons for the current form. This way you can select actions without using the mouse

Navigate through controls grouped together

Up
Down
Left
Right

Using the cursor keys you can quickly move between grouped controls

Close form

Closes the current form window

Restore window position

If some form window parameters are lost, this combination allows you to return everything back

Hotkeys: working with lists and trees

The hotkeys in this section will help you work effectively without using a mouse in numerous lists and trees that are actively used in various configuration objects on the 1C:Enterprise 8 platform.

Table 5

Hotkeys for working with lists and trees

Action

Keyboard shortcuts

How the program works

Opens the element on which the cursor is placed for editing. The key is similar to the "Edit" action on the standard form button bar

Update

Ctrl + Shift + R
F5

Updates data in a list or tree. This is especially true for dynamic lists (for example, a list of documents) when auto-update is not enabled for them

Copy

Creates a new list item using the current item as a template. Similar to the "Add by copy" button

A new group

Creates new group. Similar to the "Add group" button

Delete a line

Directly delete the current element. Attention! Use this combination with extreme caution in dynamic lists, since deletion cannot be undone

Move a line up

Ctrl + Shift + Up

In lists where line ordering is allowed, allows you to move the current line up. Similar to the "Move Up" button

Move a line down

Ctrl + Shift + Down

In lists where line ordering is allowed, allows you to move the current line down. Similar to the "Move Down" button

Move element to another group

Ctrl + Shift + M
Ctrl+F5

Allows you to quickly move the current element (for example, a directory) to another group

Go one level down while simultaneously expanding the group

Moves inside the folder where the cursor was placed

Go up one level (to "parent")

Goes to the top of the folder you were in

Finish editing

Completes editing a list item and saves the changes.

Stop searching

Aborts the search

Expand tree node

Used where tree nodes marked with "+" or "-" are available

Close tree node

Expand all tree nodes

Changing a checkbox

Inverts the value of the current element's checkbox (turns it on or off)

Hotkeys: input field

Entry field- an actively used control element in many places in configuration forms. Hotkeys for an input field allow you to quickly perform frequently used actions on it. It is especially useful to use these keys where the configuration developer has not provided the input field control buttons you need.

Table 6

Hotkeys for the input field

Action

Keyboard shortcuts

How the program works

Similar to the behavior when editing regular text, it allows you to either add new characters to the old ones when entering, or overwrite the old ones with new ones

Select button

Selecting the appropriate object associated with the input field (for example, selecting the desired document from a list). Similar to the "Select" input field button

Open button

Ctrl + Shift + F4

Opens the form of the selected object in the current input field. Same as clicking the "Open" input field button

Clear field

Clear an input field from its current value

Working with typed text in an input field

Ctrl + BackSpace

Go to the beginning of the line

Go to end of line

Clicking the Mouse Pointer on the Up Button for an Adjustment Button

Use adjustment if enabled in the input field. For example, changing dates, counters, etc. Similar to pressing the "up" button of the input field regulator

Clicking the Mouse Pointer Down on an Adjustment Button

Use adjustment if enabled in the input field. For example, changing dates, counters, etc. Similar to pressing the "down" button of the input field regulator

Hot keys: image field

Picture field- this is a standard element of the 1C:Enterprise 8 platform for displaying graphic images. Hot keys will help, for example, to comfortably view an image located in the picture field.

Table 7

Hotkeys for the image field

Action

Keyboard shortcuts

How the program works

Zoom in

Scales the picture

Zoom out

Scroll

Up
Down
Left
Right

Moving around the picture

Scroll up window size

Scroll down window size

Scroll window size left

Scroll one window size to the right

Hotkeys: Spreadsheet Document Editor

This section contains grouped hotkeys for various spreadsheet documents. They can be very useful if you frequently edit data in such documents.

Table 8

Hotkeys for the spreadsheet editor

Action

Keyboard shortcuts

How the program works

Go to cell

Opens a dialog box to move to a cell with column/row coordinates

Moving through cells

Up
Down
Left
Right

Moves the cursor through table cells

Move through cells to the next filled or empty one

Ctrl + (Up, Down, Left, Right)

Moves the cursor through filled table cells

Selecting cells

Shift + (Up, Down, Left, Right)

Selects an area of ​​cells starting with the current one

Scroll up page

Flips through a spreadsheet document

Scroll down page

Scroll left one page

Scroll right one page

Go to editing cell contents

Enables cell content editing mode

Switching edit/input mode in a cell

Go to the beginning of the line

Moves the cursor to the beginning of the line

Go to end of line

Moves the cursor to the end of the line

Go to the beginning of the text

Go to end of text

Setting the name of the current area

Ctrl + Shift + N

Sets the name of the current cell area

Hotkeys: text document editor

Hotkeys when editing text in text areas and documents can significantly speed up and simplify the process.

Table 9

Hotkeys for the editor text documents

Action

Keyboard shortcuts

How the program works

Toggle insert/replace mode

Allows you to either add new characters to the old ones when entering, or overwrite the old ones with new ones

Go to the beginning of the line

Moves the cursor to the beginning of the current line

Go to end of line

Moves the cursor to the end of the current line

Select to start of line

Selects text to the beginning of the line

Select to end of line

Selects text to the end of the line

Go to the beginning of the text

Moves the cursor to the beginning of the text

Go to end of text

Moves the cursor to the end of the text

Select to start of text

Ctrl + Shift + Home

Selects from the cursor to the beginning of the text

Select to end of text

Ctrl + Shift + End

Selects from the cursor to the end of the text

Scroll up one line

Flipping through a text document

Scroll down one line

Go to the beginning of the previous word

Go to the beginning of the next word

Select previous word

Ctrl + Shift + Left

Quick selection words (characters separated by spaces)

Select next word

Ctrl + Shift + Right

Scroll up page

Flipping through a text document

Scroll down page

Select previous page of text

Highlights text page by page

Select next page of text

Shift + Page Down

Remove selection

Removes selection

Go to line

Moves the cursor to line number

Delete the character to the left of the cursor

Deletes the character to the left of the cursor

Delete the character to the right of the cursor

Deletes the character to the right of the cursor

Delete the word to the left of the cursor

Ctrl + BackSpace

Deletes the word to the left of the cursor

Delete the word to the right of the cursor

Deletes the word to the right of the cursor

Set/remove bookmark

Marks the line you need

Next bookmark

Moves the cursor between bookmarked lines

Previous bookmark

Delete current line

Deletes the current line

Move block to the right

Moves the selected block of text to the right

Move block to the left

Moves the selected block of text to the left

You can exit the loop and transfer control to the first executable statement following the loop by using the Abort operator. To skip some of the loop statements and move on to the next iteration, use the Continue statement. In this case, control is transferred to the operator at the beginning of the loop, to the For or While operator. The Abort and Continue operators are not used separately, but are built into “if” constructs.

Example. Report the value of the first non-periodic constant numeric type.

// Procedure that prints the value of the first non-periodic constant of numeric type

// Runs from processing Sample procedure Execute()

// Output flag

totalConstant = Metadata.Constant(); for in = 1 for all Constant loop

if Metadata.Constant(in).Periodic = 1 then

continue; // Transfer control to the operator For endIf;

if Metadata.Constant(in).Type = "Number" then

ideas = Metadata.Constant(in).Identifier;

Report(iden +" " + Constant.GetAttribute(iden)); // Balance of Days 1 Output flag = 1;

interrupt; // Exit the loop early For

endIf; endCycle; // For

if Output flag = 0 then

endProcedure // Execute

Comment. Sometimes programmers in the For loop, instead of the Abort operator, resort to changing the value of the loop variable in. So, in our case, the Abort operator could be replaced by the operator

in = totalConst;

Such actions, however, are classified as bad programming style.

Some programmers believe that loop interrupt operators (in 1C these are Continue and Abort) worsen the structure of the program, and therefore, whenever possible, refuse to use them. Instead it is used combining conditions.

Let us also follow the principles structured programming, by writing code that solves the above problem using the union of conditions. In this code, we will have to abandon the For loop, replacing it with the While loop.

// A procedure that uses a combination of conditions and prints the value of the first

// non-periodic constant of numeric type. Runs from processing Sample procedure Execute()

variable allConstants, Output flag, in, ideas; ClearMessageWindow();

// Output flag will take the value 1 if detected

// non-periodic constant of numeric type Output flag = 0;

totalConstant = Metadata.Constant();

in = 1; // Constant number for now (in<= всегоКонстант) и (флагВывода = 0) цикл

if (Metadata.Constant(in).Periodic = 0) and (Metadata.Constant(in).Type = "Number") then

ideas = Metadata.Constant(in).Identifier; Report(iden + " " + Constant.GetAttribute(iden)); Output flag = 1;

endIf;

in = in + 1; // Don't forget to move to the next constant end of the Loop; // For

if Output flag = 0 then

Report("There are no non-periodic constants of numeric type in the configurator."); endIf;

endProcedure // Execute

In the above code, the union of conditions is used when writing the LP twice: (in<= всегоКонстант) и (флагВывода = 0)

(Metadata.Constant(in).Periodic = 0) and (Metadata.Constant(in).Type = "Number") This allowed us to exclude the Continue and Abort operators from the procedure.