小编Ble*_*ess的帖子

使用JMH计算指标

如何使用JMH计算CPU时间和内存量?例如,我有:代码:

@State(Scope.Thread)
@BenchmarkMode(Mode.All)
public class JMHSample_My {

    int x = 1;
    int y = 2;

    @GenerateMicroBenchmark
    public int measureAdd() {
        return (x + y);
    }

    @GenerateMicroBenchmark
    public int measureMul() {
        return (x * y);
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(".*" + JMHSample_My.class.getSimpleName() + ".*")
                .warmupIterations(5)
                .measurementIterations(5)
                .forks(1)
                .build();

        new Runner(opt).run();
    }
}
Run Code Online (Sandbox Code Playgroud)

结果:

Benchmark                  Mode   Samples         Mean   Mean error    Units
JMHSample_My.measureAdd    thrpt         5  1060579.757    39506.950   ops/ms

JMHSample_My.measureMul    thrpt         5  1046872.684    79805.116 …
Run Code Online (Sandbox Code Playgroud)

java benchmarking cpu-usage jmh

6
推荐指数
1
解决办法
3363
查看次数

为什么 Knex.js 以数组形式返回 max('value') ?

我想从表中找到最大值:

knexClient
    .queryBuilder()

    .withSchema('myschema')
    .from('mytable')
    .where({some_query})
    .max('value');
Run Code Online (Sandbox Code Playgroud)

它将所需的值作为具有单个元素的数组返回:[{max: 1000}]

为什么它返回一个数组,而不仅仅是一个数字或一个对象?

javascript node.js knex.js

5
推荐指数
1
解决办法
6377
查看次数

编译时出现graphQL错误

我正在阅读本教程:https : //www.gatsbyjs.org/blog/2017-07-19-creating-a-blog-with-gatsby/

我已经完成了所有工作,并且遇到了graphQL编译错误:

GraphQL Error There was an error while compiling your site's GraphQL queries.
Invariant Violation: GraphQLParser: Unknown argument `formatString`. 
Source: document `BlogPostByPath` file: `GraphQL request`.
Run Code Online (Sandbox Code Playgroud)

这是我的查询:

export const pageQuery = graphql`
  query BlogPostByPath($path: String!) {
    markdownRemark(frontmatter: { path: { eq: $path } }) {
      html
      frontmatter {
        date(formatString: "MMMM DD, YYYY")
        path
        title
      }
    }
  }
`
;
Run Code Online (Sandbox Code Playgroud)

编译错误指向日期对象,当我删除它时,日期编译错误就消失了。我的日期对象有什么问题?

javascript reactjs graphql gatsby

5
推荐指数
1
解决办法
743
查看次数

使Label,bbox或axes.text的边框与python matplotlib中的Graph的刺齐平

对于某些手稿,我需要将我的图表标签准确地放置在右上角或左上角。标签需要一个边框,边框的厚度应与图形的刺相同。目前我这样做是这样的:

import matplotlib.pyplot as plt
import numpy as np
my_dpi=96
xposr_box=0.975 
ypos_box=0.94
nrows=3
Mytext="label"
GLOBAL_LINEWIDTH=2
fig, axes = plt.subplots(nrows=nrows, sharex=True, sharey=True, figsize=
               (380/my_dpi, 400/my_dpi), dpi=my_dpi)
fig.subplots_adjust(hspace=0.0001)
colors = ('k', 'r', 'b')
for ax, color in zip(axes, colors):
    data = np.random.random(1) * np.random.random(10)
    ax.plot(data, marker='o', linestyle='none', color=color)

for ax in ['top','bottom','left','right']:
    for idata in range(0,nrows):
        axes[idata].spines[ax].set_linewidth(GLOBAL_LINEWIDTH)


axes[0].text(xposr_box, ypos_box , Mytext, color='black',fontsize=8,
             horizontalalignment='right',verticalalignment='top', transform=axes[0].transAxes,
             bbox=dict(facecolor='white', edgecolor='black',linewidth=GLOBAL_LINEWIDTH)) 

plt.savefig("Label_test.png",format='png', dpi=600,transparent=True)
Run Code Online (Sandbox Code Playgroud)

图片1

所以我用参数控制盒子的位置:

xposr_box=0.975 
ypos_box=0.94
Run Code Online (Sandbox Code Playgroud)

如果更改图的宽度,则框的位置也会更改,但是框的顶部和右侧(或左侧)脊线应始终直接位于图形刺的顶部:

import matplotlib.pyplot as plt
import numpy as np
my_dpi=96
xposr_box=0.975 …
Run Code Online (Sandbox Code Playgroud)

python text label matplotlib

5
推荐指数
1
解决办法
697
查看次数

如何使用GitHub Actions对构建工件进行版本控制?

我的用例是我希望每个构建/运行的工件都有一个唯一的版本号。在使用诸如CircleCI,Travis等当前工具的情况下,有可用的内部版本号,基本上它是一个总会增加的计数器。因此,我可以创建类似的版本字符串0.1.0-27。即使对于相同的提交,此计数器也会每次增加。

如何使用GitHub Actions做类似的事情?Github操作仅提供GITHUB_SHA和GITHUB_REF。

versioning automation github continuous-delivery github-actions

5
推荐指数
2
解决办法
665
查看次数

如何在颤动中创建具有固定宽度和高度的彩盒?

我正在尝试创建具有固定宽度和高度的彩色盒子.怎么做到这一点?

dart flutter

4
推荐指数
1
解决办法
9754
查看次数

在django中编写组合框的最佳方法是什么?

我尝试在django中制作一个组合框.我只发现用HTML做.是否有基于表单的django代码来执行此操作?例如,我想要一个我可以选择城市的组合框,然后选择并点击提交以将城市发送到另一个页面.谢谢

html python django

2
推荐指数
2
解决办法
9156
查看次数

示例项目无法启动

配置文件

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.example.demo.resolver.Mutation;
import com.example.demo.resolver.Query;

import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import static com.coxautodev.graphql.tools.SchemaParser.newParser;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private static Query query;

    @Autowired
    private static Mutation mutation;

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder;
    }

    @Autowired
    public GraphQL graphQL() {
        return GraphQL.newGraphQL(graphQLSchema())
                .build();
    }


    public static GraphQLSchema graphQLSchema(){
        return newParser()
                .file("schema.graphqls")
                .resolvers(query,mutation)
                .build()
                .makeExecutableSchema();
    }

}
Run Code Online (Sandbox Code Playgroud)

图式

type User {
  uid: Long!
  name: …
Run Code Online (Sandbox Code Playgroud)

mysql rethinkdb spring-boot graphql-java

2
推荐指数
1
解决办法
2362
查看次数

map [string] interface {}以使用json标签构造

我需要将map[string]interface{}其键为json标记名称的转换为struct

type MyStruct struct {
    Id           string `json:"id"`
    Name         string `json:"name"`
    UserId       string `json:"user_id"`
    CreatedAt    int64  `json:"created_at"`
}
Run Code Online (Sandbox Code Playgroud)

map[string]interface{}有按键idnameuser_idcreated_at。我需要将其转换为struct

go

1
推荐指数
2
解决办法
3482
查看次数