Only show user-presets in favorite sidebar
[ardour.git] / scripts / _split_benchmark.lua
1 -- [disable CPU freq scaling for benchmark]
2 -- create a session
3 -- add 16 mono tracks
4 -- record 2-3 mins on each track starting at 00:00:00:00
5 -- rewind the playhead to 00:00:00:00
6 -- run this script in  Menu > Window. Scripting  10 times
7 ardour { ["type"] = "EditorAction", name = "Split Benchmark" }
8
9 function factory (params) return function ()
10
11         function split_at (pos)
12                 local add_undo = false -- keep track if something has changed
13                 Session:begin_reversible_command ("Auto Region Split")
14                 for route in Session:get_tracks():iter() do
15                         local playlist = route:to_track():playlist ()
16                         playlist:to_stateful ():clear_changes ()
17                         for region in playlist:regions_at (pos):iter () do
18                                 playlist:split_region (region, ARDOUR.MusicSample (pos, 0))
19                         end
20                         if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then
21                                 add_undo = true
22                         end
23                 end
24                 if add_undo then
25                         Session:commit_reversible_command (nil)
26                 else
27                         Session:abort_reversible_command ()
28                 end
29         end
30
31         function count_regions ()
32                 local total = 0
33                 for route in Session:get_tracks():iter() do
34                         total = total + route:to_track():playlist():region_list():size()
35                 end
36                 return total
37         end
38
39         for x = 1, 3 do
40                 local playhead = Session:transport_sample ()
41
42                 local step = Session:samples_per_timecode_frame()
43                 local n_steps = 20
44
45                 local t_start = ARDOUR.LuaAPI.monotonic_time ()
46                 for i = 1, n_steps do
47                         split_at (playhead + step * i)
48                 end
49                 local t_end = ARDOUR.LuaAPI.monotonic_time ()
50
51                 Session:request_locate((playhead + step * n_steps), false, 5)
52                 print (count_regions (), (t_end - t_start) / 1000 / n_steps)
53                 collectgarbage ();
54                 ARDOUR.LuaAPI.usleep(500000)
55         end
56
57
58 end end