我写了一个简单的测试,它创建一个变量,用零初始化它并增加100000000次.
C++在0.36秒内完成.原始C#版本在0.33s新的0.8s F#在12秒内.
我不使用任何函数,因此默认情况下问题不在于泛型
F#代码
open System
open System.Diagnostics
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
[<EntryPoint>]
let main argv =
let N = 100000000
let mutable x = 0
let watch = new Stopwatch();
watch.Start();
for i in seq{1..N} do
x <- (x+1)
printfn "%A" x
printfn "%A" watch.Elapsed
Console.ReadLine()
|> ignore
0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)
C++代码
#include<stdio.h>
#include<string.h>
#include<vector>
#include<iostream>
#include<time.h>
using namespace std;
int main() …
Run Code Online (Sandbox Code Playgroud) 来自ImageProcessor repo 的引用
我们已经有了一个MyGet包存储库 - 用于前沿/开发NuGet版本.
该链接指向一些json文件.
我以前用id安装NuGet包.我该怎么办json?
以下类型提供程序旨在创建GeneratedNamespace.MyType
接受类型的静态参数string
并仅包含空构造函数
namespace TypeProviderTest
open Microsoft.FSharp.Core.CompilerServices
open ProviderImplementation.ProvidedTypes
open System.Reflection
open System
[<TypeProvider>]
type MyTypeProvider(config:TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
let namespaceName="GeneratedNamespace"
let assembly = Assembly.LoadFrom(config.RuntimeAssembly)
//Provides definition, based on type parameters
let instantiationFunction typeName (typeParams:obj[]) =
match typeParams with
| [|:? string as param|] ->
//Creates an empty non-erased type
let definition = ProvidedTypeDefinition(
assembly,
namespaceName,
typeName,
Some typedefof<Object>,
IsErased = false
)
//Creates an empty constructor
let emptyCtor = ProvidedConstructor (parameters = [])
//Provides a …
Run Code Online (Sandbox Code Playgroud) 我遇到类似这样的问题:LUA和Corona错误:尝试调用方法''(无值) - 让我疯狂 我有一个TCell类:
local TCell={};
local cell_mt = { __index=TCell };
function TCell.new(_contents_name,_x,_y)
...
local ncell=
{
...
};
function ncell:setup()
...
end
ncell:setup();
return setmetatable(ncell,cell_mt);
end
return TCell;
Run Code Online (Sandbox Code Playgroud)
我有2d TCell引用数组称为单元格.当我分配
cells[ind1][ind2]=cells[ind3][ind4]
Run Code Online (Sandbox Code Playgroud)
细胞[ind1] [ind2]开始失去一些属性.如果我正确理解了上面的链接,那就是失去了metatable关联.我需要再次使用setmetatable吗?如果未在TCell机构中完成任务,我该怎么办?
UPD.
reset_metatable=function(target)
return setmetatable(target,cell_mt);
end;
cells[ind1][ind2]=cells[ind3][ind4];
cells[ind1][ind2]=cells[ind1][ind2]:reset_metatable();
Run Code Online (Sandbox Code Playgroud)
不是很有帮助.upd2:删除所有未与摄像头连接的代码.Camera和TCell没有enterframe.问题似乎在于metatables.输出给出NOW 6 1宽度i 50并且在它开始之后6 1宽度为零
-----------------------------------------------------------------------------------------
--
-- Main Cycle
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "physics" library
local physics = require "physics"
--control_circle=display.newImageRect(C.INTERFACE_DIR..C.INTERFACE_CONTROL_CIRCLE or C.EMPTY_IMAGE,C.CARS_W,C.CARS_W,true);
local events_added=false; …
Run Code Online (Sandbox Code Playgroud) 这是我的着色器,它将一种颜色替换为另一种颜色:
Shader "Custom/SwapColors"
{
Properties
{
_MainTex("Texture",2D)="white"{}
swap_from("Swap From",COLOR)=(1,1,1,1)
swap_to("Swap To",COLOR)=(1,1,1,1)
threshold("Threshold",Float)=0.00001
}
SubShader
{
Tags
{
"Queue"="Transparent"
}
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 swap_from;
float4 swap_to;
float threshold;
struct VertexInput
{
float4 pos:POSITION;
float2 uv:TEXCOORD0;
};
struct FragmentInput
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
FragmentInput vert(VertexInput data)
{
FragmentInput res;
res.pos=mul(UNITY_MATRIX_MVP,data.pos);
res.uv=data.uv;
return res;
}
bool eq(fixed f,fixed s)
{
return abs(f-s)<threshold;
}
float4 frag(FragmentInput data):COLOR
{
float4 res=tex2D(_MainTex,data.uv.xy).rgba; …
Run Code Online (Sandbox Code Playgroud) 我想用O(1)
复杂度和O(n_max)
预处理来计算第n个Fibonacci数.
要做到这一点,我需要存储以前计算的值,如在此C++代码中:
#include<vector>
using namespace std;
vector<int> cache;
int fibonacci(int n)
{
if(n<=0)
return 0;
if(cache.size()>n-1)
return cache[n-1];
int res;
if(n<=2)
res=1;
else
res=fibonacci(n-1)+fibonacci(n-2);
cache.push_back(res);
return res;
}
Run Code Online (Sandbox Code Playgroud)
但它依赖于榆树不允许的副作用.
似乎rm -rf
在docker容器中只能处理文件.
docker run ubuntu /bin/bash -c 'sudo rm -rf ./mydir; ls'
Run Code Online (Sandbox Code Playgroud)
它列出mydir
目录而不打印任何错误.
我使用ubuntu 14.04作为主机和图像.
编辑:
我认为在我将另一个文件添加到目录后出现了错误,但我错了.最后,更改存储驱动程序有助于解决问题.
我试着按照这个教程:http://t4-editor.tangible-engineering.com/blog/how-to-generate-multiple-output-files-from-a-single-t4-template.html
与visual studio 2015(.Net 4.5)
错误示例项目:http://www.filedropper.com/t4fail
我使用以下源创建了Template1.tt:
<#@ include file="TemplateFileManagerV2.1.ttinclude" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="System.Windows.Forms" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#
var manager = TemplateFileManager.Create(this);
#>
Run Code Online (Sandbox Code Playgroud)
我TemplateFileManagerV2.1.ttinclude
从模板库添加到我的项目中.
然后我收到一个错误:
'Microsoft.VisualStudio.TextTemplating.IDebugTextTemplatingEngine'在未引用的程序集中定义.您必须添加对程序集"Microsoft.VisualStudio.TextTemplating.Interfaces.11.0,Version = 11.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"的引用.
所以我添加了引用
C:\ WINDOWS\Microsoft.NET \装配\ GAC_MSIL\Microsoft.VisualStudio.TextTemplating.11.0\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.11.0.dll
和
C:\ WINDOWS\Microsoft.NET \装配\ GAC_MSIL\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll
我的项目,但没有改变.
错误在以下方法里面 .ttinclude
public …
Run Code Online (Sandbox Code Playgroud) 我仅限于.net 3.5,并希望在F#3.0中使用Reactive Extensions.
显然,F#和RX引入了不同的版本 System.IObservable<T>
open System.Reactive
open System.Timers
open System
[<EntryPoint>]
let main argv =
let timer = new Timer(500.0)
timer.AutoReset <- true
timer.Start()
timer.Elapsed
|> Observable.scan (fun i _ -> i + 1) (-1)
:> IObservable<int>
|> ignore
0
Run Code Online (Sandbox Code Playgroud)
这失败了:类型'System.IObservable'与'System.IObservable'类型不兼容
可以同时使用两者吗?或者是否有与.net 3.5兼容的RX版本没有冲突?我也尝试寻找rx 1的来源,但没有找到,虽然我不确定它是否有用
当我在dev cpp运行这个程序时,任务管理器说它大约是79 MB.使用gnu c ++ 4.7的代码表示它是79112千字节
#include<stdio.h>
const int N=10010,K=1010;
struct TPos
{
int charge;
bool ex;
TPos()
{
charge=1<<30;
ex=false;
}
};
TPos d[N][K];
int main()
{
while(1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当ex parametr被评论时:
#include<stdio.h>
const int N=10010,K=1010;
struct TPos
{
int charge;
//bool ex;
TPos()
{
charge=1<<30;
//ex=false;
}
};
TPos d[N][K];
int main()
{
//while(1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它只有39536 KB.我认为布尔值应该使用一个字节.为什么它的尺寸加倍?