Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update weight-template and some related comments.
  • Loading branch information
hzy1919 committed May 10, 2022
commit b5978b2a2330d90f922472364cdc9d01ee81e26c
12 changes: 6 additions & 6 deletions .maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
{{weightAsNanoseconds benchmark.base_weight}}
({{weightAsNanoseconds benchmark.base_weight}} as Weight).saturating_mul(WEIGHT_PER_NANOS)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{weightAsNanoseconds cw.error}}
.saturating_add({{weightAsNanoseconds cw.slope}}.saturating_mul({{cw.name}} as Weight))
// Standard Error: {{weightAsNanoseconds cw.error}} NS
.saturating_add(({{weightAsNanoseconds cw.slope}} as Weight).saturating_mul(WEIGHT_PER_NANOS).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
Expand Down Expand Up @@ -92,10 +92,10 @@ impl WeightInfo for () {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
{{weightAsNanoseconds benchmark.base_weight}}
({{weightAsNanoseconds benchmark.base_weight}} as Weight).saturating_mul(WEIGHT_PER_NANOS)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{weightAsNanoseconds cw.error}}
.saturating_add({{weightAsNanoseconds cw.slope}}.saturating_mul({{cw.name}} as Weight))
// Standard Error: {{weightAsNanoseconds cw.error}} NS
.saturating_add(({{weightAsNanoseconds cw.slope}} as Weight).saturating_mul(WEIGHT_PER_NANOS).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
Expand Down
6 changes: 3 additions & 3 deletions utils/frame/benchmarking-cli/src/pallet/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
{{weightAsNanoseconds benchmark.base_weight}}
({{weightAsNanoseconds benchmark.base_weight}} as Weight).saturating_mul(WEIGHT_PER_NANOS)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{weightAsNanoseconds cw.error}}
.saturating_add({{weightAsNanoseconds cw.slope}}.saturating_mul({{cw.name}} as Weight))
// Standard Error: {{weightAsNanoseconds cw.error}} NS
.saturating_add(({{weightAsNanoseconds cw.slope}} as Weight).saturating_mul(WEIGHT_PER_NANOS).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
Expand Down
10 changes: 4 additions & 6 deletions utils/frame/benchmarking-cli/src/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ where
s
}

/// A Handlebars helper to add an underscore after every 3rd character,then format it,
/// i.e. a separator for large numbers : 123000000 -> 123_000 * WEIGHT_PER_NANOS.
/// A Handlebars helper to convert to NS as a unit and add an underscore after every 3rd character,
/// i.e. a separator for large numbers : 123000000 -> 123_000 NS.
#[derive(Clone, Copy)]
pub struct WeightAsNanoseconds;

Expand All @@ -88,8 +88,8 @@ impl handlebars::HelperDef for WeightAsNanoseconds {
}
}

/// Add an underscore after every 3rd character, then format it, i.e. a separator for large numbers:
/// 123000000 -> 123_000 * WEIGHT_PER_NANOS.
/// Convert to NS as a unit and add an underscore after every 3rd character,
/// i.e. a separator for large numbers: 123000000 -> 123_000 NS.
fn weight_as_nanoseconds<Number>(i: Number) -> String
where
Number: std::string::ToString,
Expand All @@ -106,8 +106,6 @@ where
}
s.insert(0, val);
}
s.insert(0, '(');
s.push_str(" as Weight).saturating_mul(WEIGHT_PER_NANOS)");
s
}

Expand Down